将RxCpp库添加到cmake项目

我想在Linux(gcc)上使用RxCpp ,但是我很难将RxCpp库适当地添加到我的cmake项目中。 我遵循克隆和构build指令,跑了:

git clone --recursive https://github.com/Reactive-Extensions/RxCpp.git cd RxCpp mkdir projects/build cd projects/build cmake -G"Unix Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -B. ../CMake make 

我试图运行make install但得到:

 make: *** No rule to make target 'install'. Stop. 

然后,我注意到我的build目录中的文件libRxCpp.so并复制它:

 cp libRxCpp.so /sw/RxCpp/2.3.0/ 

我在Clion中创build了一个新项目,它使用cmake和修改后的CMakeLists.txt如下所示:

 cmake_minimum_required(VERSION 3.6) project(RxCpp_Example) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # my try to add library RxCpp set(RxCpp_Lib_PATH /sw/RxCpp/2.3.0/) find_library(RxCpp_Lib NAMES libRxCpp.so PATHS ${RxCpp_Lib_PATH}) target_link_libraries(RxCpp_Example ${RxCpp_Lib}) set(SOURCE_FILES main.cpp) add_executable(RxCpp_Example ${SOURCE_FILES}) 

但是,更新cmake项目(或在terminal中运行cmake)时出现错误:

 CMake Error at CMakeLists.txt:9 (target_link_libraries): Cannot specify link libraries for target "RxCpp_Example" which is not built by this project. 

我究竟做错了什么? 如何将RxCpp库添加到我的cmake项目?

您在使用add_executable创建目标之前调用了add_executable 。 像这样改变你的cmake文件:

 find_library(RxCpp_Lib NAMES libRxCpp.so PATHS ${RxCpp_Lib_PATH}) set(SOURCE_FILES main.cpp) add_executable(RxCpp_Example ${SOURCE_FILES}) target_link_libraries(RxCpp_Example ${RxCpp_Lib})