cmake error - linking absolute path
I have a problem with a linking error that is killing me! Any intuition on how to solve this would be awesome!
Background:
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)
~/Projects/ROS/robot_ws/src/gist_extractor/src
gist_extractor.cpp
#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&)':
gist_extractor.cpp:(.text._ZN13GistExtractor7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE[_ZN13GistExtractor7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE]+0x133):
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
}
Have you run
nm
or a similar tool on your library to confirm that it actually containscolor_gist_scaletab()
?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.Fixed the issue. The bug was very subtle. Please see original stackoverflow post for detailed problem statement and explanation.