linking external libraries

Requests regarding how to set up experiments in ARGoS.
Elendurwen
Posts: 41
Joined: Sat Aug 24, 2013 5:08 pm
Contact:

linking external libraries

Postby Elendurwen » Thu Aug 11, 2016 6:26 pm

I am using some functionality from the gsl library, which I have installed using homebrew into /usr/local/Cellar/gsl/1.16/ and macports into /opt/local/lib

When I compile my code, I get a linking error

Code: Select all

[ 13%] Linking CXX shared library libbaseRobot.dylib Undefined symbols for architecture x86_64: "_gsl_ran_levy", referenced from: BaseRobot::DoLevyWalk() in baseRobot.cpp.o "_gsl_rng_alloc", referenced from: BaseRobot::Init(ticpp::Element&) in baseRobot.cpp.o "_gsl_rng_default", referenced from: BaseRobot::Init(ticpp::Element&) in baseRobot.cpp.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [controllers/libbaseRobot.dylib] Error 1 make[1]: *** [controllers/CMakeFiles/baseRobot.dir/all] Error 2 make: *** [all] Error 2
so it seems that the compiler cannot link the library. Can I set this somehow in the CMakeLists?

In the CMakeLists.txt of my project, I tried:

Code: Select all

# Set ARGoS link dir link_directories(${ARGOS_LIBRARY_DIRS} /usr/local/Cellar/gsl/1.16/lib/)
but that did not help.

Another weird thing is that after running cmake, the file build/CMakeCache.txt has:

Code: Select all

CMAKE_EXE_LINKER_FLAGS:STRING= -L/opt/local/lib
there is a library for gsl in that location, yet the compiling doesn't work. Would anyone be able to help? I am on Mac OS El captain, using gcc version 7.3.0

pincy
Site Admin
Posts: 632
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

Re: linking external libraries

Postby pincy » Thu Aug 11, 2016 6:36 pm

Hi Lenka,

The problem you're encountering can be solved by configuring CMake properly (have a look also here: https://cmake.org/cmake/help/v3.2/module/FindGSL.html). Something like this:

Code: Select all

find_package(GSL REQUIRED) include_directories(${GSL_INCLUDE_DIRS})
Then, each library/executable that needs to have GSL, you do:

Code: Select all

add_library(mylib ...) target_link_libraries(mylib ... ${GSL_LIBRARIES})
NOTE: the current development version of ARGoS doesn't use GSL anymore. It will be released soon.

Cheers,
Carlo
I made ARGoS.

Elendurwen
Posts: 41
Joined: Sat Aug 24, 2013 5:08 pm
Contact:

Re: linking external libraries

Postby Elendurwen » Sat Aug 13, 2016 1:00 am

Great, that worked, thanks!


Return to “How to... ?”