C++ cpprestsdk使用vcpkg、cmake-can';找不到包含文件

C++ cpprestsdk使用vcpkg、cmake-can';找不到包含文件,c++,cmake,cpprest-sdk,vcpkg,C++,Cmake,Cpprest Sdk,Vcpkg,我正在将一个Windows项目移植到使用cpprestsdk的CentOS Linux。我在Windows上使用vcpkg,我想我会使用vcpkg(和cmake)来引入和构建包,并将libs和头文件“公开”到我的项目中。序列无法尝试获取源代码“已知”的包头文件。这就是我所做的 $ vcpkg install boost cpprestsdk $ vcpkg integrate install Applied user-wide integration for this vcpkg root. C

我正在将一个Windows项目移植到使用cpprestsdk的CentOS Linux。我在Windows上使用vcpkg,我想我会使用vcpkg(和cmake)来引入和构建包,并将libs和头文件“公开”到我的项目中。序列无法尝试获取源代码“已知”的包头文件。这就是我所做的

$ vcpkg install boost cpprestsdk
$ vcpkg integrate install
Applied user-wide integration for this vcpkg root.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=/vcpkg/scripts/buildsystems/vcpkg.cmake"

$ cd <source>
$ vi CMakeLists.txt
cmake_minimum_required(VERSION 2.8.9)
project(Domain)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -I../ ")
file(GLOB SOURCES "*.cpp")

#Generate the shared library from the sources
add_library(Domain SHARED ${SOURCES})

install(TARGETS Domain DESTINATION ../lib)

$ cmake -DCMAKE_TOOLCHAIN_FILE=/vcpkg/scripts/buildsystems/vcpkg.cmake -G "Unix Makefiles" .
$ make
[  7%] Building CXX object CMakeFiles/Domain.dir/BaseDataFactory.cpp.o
In file included from /src/Domain/stdafx.h:4:0,
             from /src/Domain/BaseDataFactory.cpp:1:
../Common/Common.h:75:26: fatal error: cpprest/json.h: No such file or directory
#include <cpprest/json.h>
然后我发现了一大堆新的错误:

CMake Error at CMakeLists.txt:7 (find_package):
Could not find a package configuration file provided by "cpprestsdk" with
any of the following names:

cpprestsdkConfig.cmake
cpprestsdk-config.cmake
cpprestConfig.cmake
cpprest-config.cmake
cpprestsdk-config.cmake确实存在于vcpkg根目录下,我可以肯定地看到vcpkg根目录下的包的有问题的头文件,但是为什么cmake生成的Makefile没有它需要构建的所有内容呢?vcpkg下的每个包是否都必须以某种方式手动包含在CMakeLists.txt文件中?

有一件事让我困惑(还不是vcpkg专家)

而它应该是
lib/cpprestsdk
IMHO(编辑:未选中SHA1版本)

@您是否尝试在系统上定位配置文件?
您是否可以尝试打印
CMAKE\u PREFIX\u路径
等,以查看vcpkg是否正确地完成了它的工作…

我发现了问题。Cpprestsdk不注册/公开任何cmake find_package()配置模块。如果做到了这一点,这就不会成为问题——生成的工具链文件将设置cmake所需的一切,以便生成包含在MakeFile中的路径

我在CMakeList.txt文件中添加了以下行,然后cmake能够找到配置文件:

set(cpprestsdk_DIR)/vcpkg/installed/x64 linux/share/cpprestsdk)


这真的非常糟糕,IMHO,必须硬编码一条路径才能找到cpprestsdk。我仍然有头文件路径问题,因此实际上还有更多的错误/丢失。一旦从vcpkg/cmake团队得到消息,我将更新此帖子。

vcpkg
不会自动向编译器添加include目录,也不会自动链接您创建的每个可执行文件的库。相反,它将目录添加到CMake环境中,在那里可以通过
find\u package()
找到配置文件或查找脚本。也就是说,使用
cpprestsdk
需要
find_包(需要cpprestsdk)
。“所有这些文件都存在于vcpkg根目录下”-很可能,您的意思是只有
cpprestsdk config.cmake
文件存在。其他名称是遵循CMake约定的CMake配置文件的替代名称。我认为这就是“vcpkg集成安装”的要点——为cmake生成工具链文件?在任何情况下,“cpprestsdk config.cmake”都存在,但找不到,这是为什么?有很多好的信息,但没有关于解决方案的建议……嗯,我的意思是vcpkg提供的工具链文件的目的是调整CMake变量(和环境变量),所以
find_package()
应该可以工作。我不知道为什么它在你的情况下不起作用,我同意,这看起来很奇怪。谢谢你的帮助。请看我的帖子。似乎cpprestsdk在cmake支持方面有缺陷…更新:至少在2.10版本,MS已经修复了这个问题,所以这个问题不再存在。
CMake Error at CMakeLists.txt:7 (find_package):
Could not find a package configuration file provided by "cpprestsdk" with
any of the following names:

cpprestsdkConfig.cmake
cpprestsdk-config.cmake
cpprestConfig.cmake
cpprest-config.cmake
install(
    FILES "${CMAKE_CURRENT_BINARY_DIR}/cpprestsdk-config.cmake"
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CPPREST_EXPORT_DIR}
  )
set(CPPREST_EXPORT_DIR cpprestsdk CACHE STRING "Directory to install CMake config files.")
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/share/cpprestsdk)