[c++] 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.

This question is related to c++ cmake libraries

The answer is


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


Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to cmake

Copy file from source directory to binary directory using CMake CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found Installing cmake with home-brew CMake does not find Visual C++ compiler What's the CMake syntax to set and use variables? How do I add a library path in cmake? How to build x86 and/or x64 on Windows from command line with CMAKE? Difference between using Makefile and CMake to compile the code Add external libraries to CMakeList.txt c++ Cmake is not able to find Python-libraries

Examples related to libraries

Gradle failed to resolve library in Android Studio Add external libraries to CMakeList.txt c++ The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files fatal error LNK1104: cannot open file 'kernel32.lib' Node.js Logging The project was not built since its build path is incomplete libstdc++-6.dll not found How to add local jar files to a Maven project? How to add additional libraries to Visual Studio project? Java out.println() how is this possible?