基于这个问题CMake cpprestsdk我尝试从cpprestsdk源代码创建一个特定的目标。首先,我将github项目克隆到
/home/user/git/cpprestsdk
然后,我创建了 CmakeLists.txt 文件
project(ProjectName)
find_package(cpprestsdk CONFIG REQUIRED)
target_link_libraries(ProjectName PRIVATE cpprestsdk::cpprestsdk_boost_internal)
和 cmake 命令:
cmake -DCMAKE_PREFIX_PATH=/home/user/git/cpprestsdk/Release/src .
并出现以下错误:
CMake Error at cpprestsdk/Release/src/cpprestsdk-config.cmake:25 (include):
include could not find load file:
/home/ebalbar/git/cpprestsdk/Release/src/cpprestsdk-targets.cmake
Call Stack (most recent call first):
CMakeLists.txt:2 (find_package)
CMake Error at CMakeLists.txt:3 (target_link_libraries):
Cannot specify link libraries for target "ProjectName" which is not built
by this project.
目标文件可以在
/home/user/git/cpprestsdk/Release/src/CMakeFiles/Export/lib/cmake/cpprestsdk/cpprestsdk-targets.cmake
下找到
所以问题是如何建立
cpprestsdk::cpprestsdk_boost_internal
目标?
提前致谢!
正如 @Tsyvarev 指出的,首先应该构建和安装库。
cmake .
cmake --build .
cmake --install . --prefix <install_folder>
然后,应用程序 CMakeList.txt 应如下所示:
cmake_minimum_required(VERSION 3.16)
# In your project's CMakeLists.txt
project(ProjectName)
set(CMAKE_PREFIX_PATH "<install_folder>")
find_package(cpprestsdk REQUIRED)
add_library(my_target SHARED main.cpp)
# Link to `cpprestsdk::cpprestsdk_openssl_internal` in your target
target_link_libraries(my_target cpprestsdk::cpprestsdk_openssl_internal)
然后我可以使用以下 cmake 命令构建应用程序:
cmake .
cmake --build .