maiermic maiermic - 1 year ago 282
Linux Question

add RxCpp library to cmake project

I'd like to use RxCpp on Linux (gcc), but I have trouble to add RxCpp library appropriately to my cmake project. I followed cloning and building instructions and ran:

git clone --recursive
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

I tried to run
make install
but got:

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

Then, I noticed the file
in my build directory and copied it:

cp /sw/RxCpp/2.3.0/

I created a new project in Clion, which uses cmake and modified
like this:

cmake_minimum_required(VERSION 3.6)

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 PATHS ${RxCpp_Lib_PATH})
target_link_libraries(RxCpp_Example ${RxCpp_Lib})

set(SOURCE_FILES main.cpp)
add_executable(RxCpp_Example ${SOURCE_FILES})

However, I get an error when updating the cmake project (or running cmake in terminal):

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

What am I doing wrong? How can I add RxCpp library to my cmake project?

Answer Source

You called target_link_libraries before creating the target with add_executable. Change your cmake file like this:

find_library(RxCpp_Lib NAMES PATHS ${RxCpp_Lib_PATH})

set(SOURCE_FILES main.cpp)
add_executable(RxCpp_Example ${SOURCE_FILES})

target_link_libraries(RxCpp_Example ${RxCpp_Lib})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download