无法在OSX上找到C ++项目的SimpleAmqpClient库

时间:2016-02-08 08:20:59

标签: c++ macos cmake

我尝试使用SimpleAmqpClient库来构建我的多代理环境以进行模拟。我在克隆了它的源代码后安装了它,使它们成为:

make
sudo make install

之后,我创建了

  

的main.cpp

文件:

#include <iostream>
#include <SimpleAmqpClient/SimpleAmqpClient.h>
using namespace std;

int main() {
    cout << "Hello, World!" << endl;
    return 0;
}

试试吧。

另外,我有以下

  

的CMakeLists.txt:

cmake_minimum_required(VERSION 3.3)
project(SampleProject)
include_directories('/usr/local/include/')

find_package(libSimpleAmqpClient REQUIRED)
include_directories(${libSimpleAmqpClient++_INCLUDE_DIRS})
set(LIBS ${LIBS} ${libSimpleAmqpClient++_LIBRARIES})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

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

所以,问题是:如何查找和链接这个库。

2 个答案:

答案 0 :(得分:0)

您需要包含该行

target_link_libraries(SampleProject ${LIBS})
行后

add_executable(SampleProject ${SOURCE_FILES})

这会使目标SampleProject的属性告诉生成器生成一个引用所需库的链接器命令。

答案 1 :(得分:0)

我已经找到了解决方案,感谢@RichardHodges。解决方案是使用

find_library()代替find_package()

最终文件如下:

  

的CMakeLists.txt

cmake_minimum_required(VERSION 3.3)
project(SampleProject)
include_directories('/usr/local/include/')

find_library(libSimpleAmqpClient REQUIRED)
include_directories(${libSimpleAmqpClient++_INCLUDE_DIRS})
set(LIBS ${LIBS} ${libSimpleAmqpClient++_LIBRARIES})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

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