Ask Your Question

cmake error - linking absolute path

asked 2016-02-26 23:58:02 -0500

drifter24 gravatar image

updated 2016-02-27 23:41:05 -0500

I have a problem with a linking error that is killing me! Any intuition on how to solve this would be awesome!


I am trying to build a source file called "gist_extractor.cpp." This source file, however, uses a function that is defined in library called lear_gist that is located in a different location on my machine. I have hardcoded absolute paths to my header files and used add_library command in cmake to make the library.

I have gone through the CMake tutorials and I'm fairly sure I'm building my library correctly and also linking correctly in my CMake. That said, I continue to get a linker error and I don't know what could be wrong.

Detailed Information

My Project Directory (where gist_extract.cpp is located)



#include "/home/andy/Development/lear_gist-1.2/gist.h"
#include "/home/andy/Development/lear_gist-1.2/standalone_image.h"
extern "C" {
#include "/home/andy/Development/lear_gist-1.2/gist.h"
#include "/home/andy/Development/lear_gist-1.2/standalone_image.h"
float *color_gist_scaletab(color_image_t*, int, int, const int *);

// some stuff 
float *gist_descriptor = color_gist_scaletab(args); //function defined in lear_gist

Lear gist is located at /Development/lear_gist-1.2 and the directory is given below. In addition, color_gist_scal

ar.ppm          gist.c  Makefile            standalone_image.h
compute_gist    gist.h  README              standalone_image.o
compute_gist.c  gist.o  standalone_image.c

CMake File

## Set Variables
set(GIST_PATH "/home/andy/Development/lear_gist-1.2")

## Specify additional locations of header files
include_directories(include ${catkin_INCLUDE_DIRS} ${GIST_PATH})

## Declare a C++ library
add_library(gist ${GIST_PATH}/standalone_image.c ${GIST_PATH}/gist.c)

## Add cmake target dependencies of the library

## Declare a C++ executable
add_executable(gist_extractor src/gist_extractor.cpp)

## Add cmake target dependencies of the executable and library above
#add_dependencies(gist_extractor ${GIST_INCLUDE}/gist.c ${GIST_INCLUDE}/standalone_image.c)

## Specify libraries to link a library or executable target against
target_link_libraries(gist_extractor gist ${catkin_LIBRARIES})

Error Statement

  CMakeFiles/gist_extractor.dir/src/gist_extractor.cpp.o: In function `GistExtractor::imageCb(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)':

undefined reference to `color_gist_scaletab(color_image_t*, int, int, int const*)'
collect2: error: ld returned 1 exit status

gist.c file

float *color_gist_scaletab(color_image_t *src, int w, int n_scale, const int *n_orientation) {
    int i;

    // some more stuff
edit retag flag offensive close merge delete


Have you run nm or a similar tool on your library to confirm that it actually contains color_gist_scaletab() ?

ahendrix gravatar image ahendrix  ( 2016-02-28 01:03:32 -0500 )edit

Please see if using an external library: C versus C++ issue helps (probably the same issue as what @ahendrix is hinting at). Also: don't use #include with absolute paths, configure your include path correctly.

gvdhoorn gravatar image gvdhoorn  ( 2016-02-28 01:46:36 -0500 )edit

Fixed the issue. The bug was very subtle. Please see original stackoverflow post for detailed problem statement and explanation.

drifter24 gravatar image drifter24  ( 2016-05-13 16:57:57 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-03-06 18:45:15 -0500

drifter24 gravatar image

I was able to fix the issue. A full description of the solution can be found in my stackoverflow post.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-02-26 23:58:02 -0500

Seen: 1,214 times

Last updated: Mar 06 '16