我正在将Windows项目移植到使用cpprestsdk的CentOS Linux。我在Windows上使用vcpkg,我以为我会使用vcpkg(和cmake)引入并构建软件包并将库和标头文件“暴露”到我的项目中。该序列未能尝试使包头文件对我的源“已知”。这就是我所做的。
$ 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>
通过将vcpkg工具链文件参数添加到cmake,我认为它应该负责公开所有包路径(lib / header)并将它们写入输出Makefile?
我尝试添加
find_package(cpprestsdk REQUIRED)
然后我收到了很多新错误:
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文件中?
答案 0 :(得分:1)
我发现了问题。 Cpprestsdk不会注册/公开任何cmake find_package()配置模块。如果这样做的话,这将不是问题-生成的工具链文件将设置cmake所需的一切,以便生成要包含在MakeFile中的路径。
我将以下行添加到CMakeList.txt文件中,然后cmake能够找到配置文件:
set(cpprestsdk_DIR“ / vcpkg / installed / x64-linux / share / cpprestsdk”)
恕我直言,这真的非常糟糕,必须硬编码找到cpprestsdk的路径。我仍然有头文件路径问题,所以实际上还有更多的错误/遗漏。一旦收到vcpkg / cmake团队的支持,我将更新此帖子。
答案 1 :(得分:0)
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专家) https://github.com/Microsoft/vcpkg/blob/master/ports/cpprestsdk/portfile.cmake#L45
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/share/cpprestsdk)
应为lib/cpprestsdk
恕我直言(未编辑SHA1版本)
@cardinalPilot您是否尝试在系统上找到配置文件?
您还可以尝试打印CMAKE_PREFIX_PATH
等以查看vcpkg是否正确执行其工作...