0
$\begingroup$

Rosanswers logo

Hello,

I am currently revisiting ROS as I want to build localization with the GTSAM library. It is important to mention that this is the first time I used an external library aside from OpenCV.

I cloned the repository into my /usr/lib folder and installed it as instructed. I then added two includes into my - otherwise functioning .h file - and tried to compile. The beginning of my .h file, the compile error and my CMakeLists.txt are shown below. Interestingly, if I comment out the second include and just include Pose2.h, compilation works. That should mean that the compiler at least finds some headers from the library, ergo it is correctly installed. The part of my cmake code which is supposed to link the library is extracted from an example project given here.

car_lib.h:

#ifndef CAR_LIB_H
#define CAR_LIB_H

// GTSAM headers
#include <gtsam/geometry/Pose2.h>
#include <gtsam/nonlinear/NonlinearFactorGraph.h>
using namespace gtsam;

// rest of file follows....

When compiling, I get the following error:

...
[100%] Linking CXX executable /home/marc/catkin_ws/devel/lib/car/car_node
[100%] Linking CXX shared library /home/marc/catkin_ws/devel/lib/libcar_lib.so
[100%] Built target car_lib
CMakeFiles/car_node.dir/src/car_node.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
/usr/local/include/gtsam/inference/Key.h:41: undefined reference to `gtsam::_defaultKeyFormatter[abi:cxx11](unsigned long)'
/usr/local/include/gtsam/inference/Key.h:52: undefined reference to `gtsam::_multirobotKeyFormatter[abi:cxx11](unsigned long)'
collect2: error: ld returned 1 exit status
car/CMakeFiles/car_node.dir/build.make:113: recipe for target '/home/marc/catkin_ws/devel/lib/car/car_node' failed
make[2]: *** [/home/marc/catkin_ws/devel/lib/car/car_node] Error 1
CMakeFiles/Makefile2:384: recipe for target 'car/CMakeFiles/car_node.dir/all' failed
make[1]: *** [car/CMakeFiles/car_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed

My CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(car)

## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  message_generation
  nav_msgs
  roscpp
  sensor_msgs
  std_msgs
)

###### GTSAM STUFF STARTS HERE

# Include GTSAM CMake tools
find_package(GTSAMCMakeTools)
#include(GtsamBuildTypes) # Load build type flags and default to Debug mode
#include(GtsamTesting)    # Easy functions for creating unit tests and scripts
#include(GtsamMatlabWrap) # Automatic MATLAB wrapper generation

# Ensure that local folder is searched before library folders
#include_directories(BEFORE "${PROJECT_SOURCE_DIR}")

###################################################################################
# Find GTSAM components
find_package(GTSAM REQUIRED) # Uses installed package
include_directories(${GTSAM_INCLUDE_DIR})

###################################################################################
# Build static library from common sources
#set(CONVENIENCE_LIB_NAME ${PROJECT_NAME})
#add_library(${CONVENIENCE_LIB_NAME} STATIC include/car/car_lib.h src/car_lib.cpp)
#target_link_libraries(${CONVENIENCE_LIB_NAME} gtsam)

###### GTSAM STUFF ENDS HER

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES car_lib
  CATKIN_DEPENDS
  geometry_msgs
  message_runtime
  nav_msgs
  roscpp
  sensor_msgs
  std_msgs
)

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

## Declare a C++ library
add_library(car_lib
  include/${PROJECT_NAME}/car_lib.h
  src/car_lib.cpp
)

add_executable(car_node src/car_node)
target_link_libraries(car_node ${catkin_LIBRARIES})
target_link_libraries(car_lib
  ${catkin_LIBRARIES}
)

Originally posted by anonymous28046 on ROS Answers with karma: 65 on 2017-06-04

Post score: 0


Original comments

Comment by gvdhoorn on 2017-06-04:\

fatal error: Eigen/Dense: No such file or directory

this is not a problem with 'libraries', but with your compiler not being able to find Eigen. For starters I would add ${catkin_INCLUDE_DIRS} to your include_directories(..) statement. And make CMake find Eigen.

Comment by anonymous28046 on 2017-06-04:
Oops. Did not copy that code snippet. ${catkin_INCLUDE_DIRS} was part of my CMakeLists.txt. How do I go about finding Eigen? The library has local copies of third party libraries, including Eigen. I have the folder /usr/lib/gtsam/gtsam/3rdparty . How can I make CMake find all of this?

Comment by anonymous28046 on 2017-06-04:
maybe I installed the library in the wrong folder? I notice that - while coding - my IDE can not find the imports from it.

Comment by anonymous28046 on 2017-06-06:
Edit: I severely changed the original text and incorporated more info and a specific case.

Comment by dalis on 2017-10-02:
did you made it work? I have the same problem

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Yes, see here.


Originally posted by anonymous28046 with karma: 65 on 2017-10-02

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.