[英]Unable to locate SimpleAmqpClient library for the C++ project on OSX
I try to use the SimpleAmqpClient library to build my multi-agent environment for simulation.我尝试使用SimpleAmqpClient库来构建我的多代理环境进行模拟。 I have installed the library after cloning its sources, making them:
我在克隆其源代码后安装了该库,使它们:
make
sudo make install
After that, I created the之后,我创建了
main.cpp
主程序
file:文件:
#include <iostream>
#include <SimpleAmqpClient/SimpleAmqpClient.h>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
just to try it out.只是为了尝试一下。
Also, I have the following另外,我有以下
CMakeLists.txt:
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})
So, the question is: how to find and link this library.所以,问题是:如何找到并链接这个库。
You need to include the line您需要包括该行
target_link_libraries(SampleProject ${LIBS})
after the line线后
add_executable(SampleProject ${SOURCE_FILES})
This imbues the target SampleProject
with properties that tell the generator to generate a linker command which reference the libraries you need.这为目标
SampleProject
了一些属性,这些属性告诉生成器生成一个链接器命令,该命令引用您需要的库。
I have found the solution, thanks to @RichardHodges.感谢@RichardHodges,我找到了解决方案。 The solution was to use
解决方案是使用
find_library()
instead of find_package()
. find_library()
而不是find_package()
。
THe final file is the following:最终文件如下:
CMakeLists.txt
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})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.