c++ nodelet crashed on invoke of method from shared library (symbol lookup error)

asked 2018-11-14 00:30:10 -0500

Gil404 gravatar image

I have a C++ ROS workspace where I have created a a static library which I would like to use from different projects (ROS packages).

However, it looks like I am missing something in the CMakeLists file of the library I have created, since when I try to execute a static method from my library I get the following error:

/opt/ros/kinetic/lib/nodelet/nodelet: symbol lookup error: /catkin_ws/devel/lib//libmy_nodelet.so: undefined symbol: _ZN14my_commons9MyLog6ROSLogEiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES6_

My library is pretty simple. contains 2 main folders: include which includes the MyLogger.hpp file and src which contains MyLogger.cpp

Here is the CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8.3)
project(my_commons)
set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")

find_package(catkin REQUIRED COMPONENTS
roscpp  
)

catkin_package(CATKIN_DEPENDS
               INCLUDE_DIRS include)


include_directories(
  ${catkin_INCLUDE_DIRS}
   include/
)
###########
## Build ##
###########

add_library(my_commons
src/MyLog.cpp
)

## Specify libraries to link a library or executable target against

set_target_properties(my_commons PROPERTIES LINKER_LANGUAGE CXX)

target_link_libraries(my_commons
                        ${catkin_LIBRARIES} 
                        ${roscpp_LIBRARIES}                         
)

#add_dependencies(name_of_package_nodelet)

install(DIRECTORY include/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
  PATTERN ".svn" EXCLUDE)

# Install library
install(TARGETS my_commons
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

in packages where I want to use it, I add my_commons under target_link_libraries

What am I missing?

Thank you very much in advance for your help.

edit retag flag offensive close merge delete