demid5111 February 2016

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

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.

Answers


Richard Hodges February 2016

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.


demid5111 February 2016

I have found the solution, thanks to @RichardHodges. The solution was to use

find_library() instead of find_package().

THe final file is the following:

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

Post Status

Asked in February 2016
Viewed 3,995 times
Voted 5
Answered 2 times

Search




Leave an answer