Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add external libraries to CMakeList.txt c++

I have my external library as shown in this picture that I create the symbolic links after:

enter image description here

and the headers related to the library in other file:

enter image description here

I'm working with ROS ubuntu and I need to add these libraries to my package to CmakeList.txt:

cmake_minimum_required(VERSION 2.4.6) include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)  rosbuild_init()  #set the default path for built executables to the "bin" directory set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) #set the default path for built libraries to the "lib" directory set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)  #common commands for building c++ executables and libraries #rosbuild_add_library(${PROJECT_NAME} src/example.cpp) #target_link_libraries(${PROJECT_NAME} another_library) #rosbuild_add_boost_directories() #rosbuild_link_boost(${PROJECT_NAME} thread) #rosbuild_add_executable(example examples/example.cpp) #target_link_libraries(example ${PROJECT_NAME})  rosbuild_add_executable(kinectueye src/kinect_ueye.cpp) 

So my question is how can I add these folders (I think the first one that I need to add I'm not sure) to my CmakeList.txt file so as I can use the classes and the methods in my program.

like image 685
Ja_cpp Avatar asked Jul 04 '14 09:07

Ja_cpp


People also ask

How do I add an external library to Visual Studio?

For adding libraries, this is very simple (if that's what you mean) Project -> properties -> configure properties -> Linker -> Input -> additional libraries. Go stand on one of the libraries in there and press enter.

How do I add a library to CLion?

Since CLion relies on CMake build system, you can do this with CMake commands. To add libraries to your project, use find_package (if you use separate libraries, for example, installed in the system) and target_link_libraries CMake commands.


1 Answers

I would start with upgrade of CMAKE version.

You can use INCLUDE_DIRECTORIES for header location and LINK_DIRECTORIES + TARGET_LINK_LIBRARIES for libraries

INCLUDE_DIRECTORIES(your/header/dir) LINK_DIRECTORIES(your/library/dir) rosbuild_add_executable(kinectueye src/kinect_ueye.cpp) TARGET_LINK_LIBRARIES(kinectueye lib1 lib2 lib2 ...) 

note that lib1 is expanded to liblib1.so (on Linux), so use ln to create appropriate links in case you do not have them

like image 86
Peter Avatar answered Oct 09 '22 19:10

Peter