将RxCpp库添加到cmake项目

时间:2016-10-07 11:10:18

标签: c++ linux c++11 gcc cmake

我想在Linux(gcc)上使用RxCpp,但我无法将RxCpp库适当地添加到我的cmake项目中。我跟着克隆并建立了说明并运行了:

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.

然后,我注意到我的构建目录中的文件libRxCpp.so并将其复制:

cp libRxCpp.so /sw/RxCpp/2.3.0/

我在Clion中创建了一个新项目,它使用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项目(或在终端中运行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项目中?

1 个答案:

答案 0 :(得分:3)

在使用target_link_libraries创建目标之前,您致电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})