本文介绍了将RxCpp库添加到cmake项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  git clone --recursive https://github.com/Reactive-Extensions/ RxCpp.git 
cd RxCpp

mkdir projects / build
cd projects / build
cmake -GUnix Makefiles-DCMAKE_C_COMPILER = gcc -DCMAKE_CXX_COMPILER = g ++ -DCMAKE_BUILD_TYPE = RelWithDebInfo -B。 ../CMake
make

我试着运行 make install 但是得到:

  make:***没有规则使目标'安装'。停止。 

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

  cp libRxCpp.so /sw/RxCpp/2.3.0/ 

我在,它使用cmake并修改 CMakeLists.txt 像这样:

<$ p

$ b set(CMAKE_CXX_FLAGS$ {CMAKE_CXX_FLAGS} -std = c ++ 11)$ b $ cmake_minimum_required(VERSION 3.6)
project(RxCpp_Example) b
#我尝试添加库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错误在CMakeLists.txt:9(target_link_libraries):
无法为目标RxCpp_Example指定链接库,该目标不是由该项目构建的

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

解决方案

您调用 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})
pre>

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 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

I tried to run make install but got:

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

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

cp libRxCpp.so /sw/RxCpp/2.3.0/

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

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})

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?

解决方案

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

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})

这篇关于将RxCpp库添加到cmake项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 16:23