45

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.

Ja_cpp
  • 2,222
  • 7
  • 22
  • 42
  • 2
    Screenshots 404 – grepsedawk May 21 '17 at 02:50
  • @Pachonk it was just a screenshot of files in a folder.. I don't have it anymore – Ja_cpp Jul 04 '17 at 08:48
  • 2
    404s are why I hate questions containing links. – Mitja Jul 24 '17 at 13:44
  • @Mitja When I posted that question I was just created my account so I didn't have enough reputations to post an image in my question without a link. Sorry! – Ja_cpp Jul 24 '17 at 13:56
  • Sorry, didn't know about those limitations. To me, it makes no sense to allow new accounts to embed links but not include images. Both can be used for spam, and links even better.. Also, I can't take my downvote from this question anymore as it is now >2hrs old (and, tbh, the question is kind of bad w/o the links working), so take an upvote to another reasonable question of yours instead. – Mitja Jul 24 '17 at 16:00
  • @Mitja that's okay! I've found the library again and I just edited my post.. thanks for pointing that out.. (@Pachonk) – Ja_cpp Aug 22 '17 at 12:36
  • 2
    @Ja_cpp next time use [`tree`](https://stackoverflow.com/a/3455675/3079302) or [something similar](https://stackoverflow.com/a/3455651/3079302). – iled Nov 13 '17 at 23:52
  • Possible duplicate of [CMake link to external library](https://stackoverflow.com/questions/8774593/cmake-link-to-external-library) – Trevor Boyd Smith Apr 26 '18 at 19:31

1 Answers1

74

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

Community
  • 1
  • 1
Peter
  • 9,045
  • 4
  • 39
  • 65
  • Like that INCLUDE_DIRECTORIES(home/jros/roskinectueye/MIXEDVISION/include/MIXEDVISION) LINK_DIRECTORIES(/home/jros/roskinectueye/MIXEDVISION/lib64) rosbuild_add_executable(kinectueye src/kinect_ueye.cpp) TARGET_LINK_LIBRARIES(kinectueye libgsl.so.0.16.0 libgslcblas.so.0.0.0) – Ja_cpp Jul 04 '14 at 09:43
  • 2
    `TARGET_LINK_LIBRARIES(kinectueye gsl gslcblas ...)` – Peter Jul 04 '14 at 09:57
  • I get this error: Linking CXX executable ../bin/kinectueye /usr/bin/ld: cannot find -lgsl /usr/bin/ld: cannot find -lHalf and for all the libraries ! – Ja_cpp Jul 04 '14 at 10:02
  • make sure you have symbolic links in your directory libgsl.so -> libgsl.so.0.16.0, etc – Peter Jul 04 '14 at 10:03
  • Yes I have it, as shown in the first image that I post – Ja_cpp Jul 04 '14 at 10:06
  • No you do not, you need libname without "numbers" at the end – Peter Jul 04 '14 at 10:13
  • create symbolic links – Peter Jul 06 '14 at 05:27
  • I do ! the file become like shortcut .. is that symbolic link ? – Ja_cpp Jul 07 '14 at 07:38
  • unfortunately yes, I get Linking CXX executable ../bin/kinectueye /usr/bin/ld: cannot find -lgsl /usr/bin/ld: cannot find -lgslcblas ..... and some others – Ja_cpp Jul 07 '14 at 08:07
  • Please run `make VERBOSE=1` and copy here the full link command for kinectueye. – Peter Jul 07 '14 at 08:14
  • I get that: make: *** No targets specified and no makefile found. Stop. – Ja_cpp Jul 07 '14 at 08:20
  • `make VERBOSE=1 kinectueye`, in the folder where you have generated build system from cmake – Peter Jul 07 '14 at 08:26
  • Sorry, I will not download the file. Please post it here. Just a link line. – Peter Jul 07 '14 at 08:37
  • Thank you @Peter It works now... I changed my package from Rosbuild to catkin. and concerning the library I change it to *.so. – Ja_cpp Jul 08 '14 at 13:57
  • What's "kinectueye"? – filip Dec 03 '18 at 09:30