How to include header file(.h) in CMakeLists.txt in gazebo
Hi, I have created header file modelpush.h and modelpush.cc under test directory. I build the code and no errors were found but when I run it using gazebo , it gives me an error
gzserver: symbol lookup error: build/libmodel_push.so: undefined symbol: _ZN6gazebo9ModelPushC1Ev
I think as I have not included my header file in CMakeLists.txt, it is because of that. So can anyone suggest me How to include header file in my CMakeLists.txt? because I have to use this header file in another c code to access the functions. Any help would highly be appreciated. Thanks!
Asked by anonymous on 2015-04-02 01:42:01 UTC
Answers
Yes ,
My CMakeLists.txt is
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
find_package(Boost REQUIRED COMPONENTS system)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
include (FindPkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(GAZEBO gazebo)
endif()
include_directories(${GAZEBO_INCLUDE_DIRS})
link_directories(${GAZEBO_LIBRARY_DIRS})
add_library(model_push SHARED model_push.cc)
target_link_libraries(model_push ${GAZEBO_LIBRARIES} ${Boost_LIBRARIES})
Asked by anonymous on 2015-04-03 00:53:14 UTC
Comments
I think the problem is not CMakeLists.txt cannot find out the header file, because if it cannot find it, it will give an error like "cannot find header file XXXXXX". Instead, the problem is gazebo cannot find the library file libmodel_push.so. So you should find out where libmodel_push.so is and export this path to env GAZEBO_PLUGIN_PATH like this:
$ export GAZEBO_PLUGIN_PATH=$GAZEBO_PLUGIN_PATH:{your libmodel_push.so path}
you should replace {your libmodel_push.so path} with the actual path.
Another tip: if you have installed gazebo_ros package, you don't have to specify this plugin path, the library file will be automatically put in {workspace}/devel/lib folder when you "catkin_make" your workspace. And then gazebo_ros will find it. But remember you should run
rosrun gazebo_ros gazebo YOUR_WORLD_FILE
Asked by winston on 2015-04-03 19:30:49 UTC
Comments
Can you post your code and CMakeLists.txt?
Asked by nkoenig on 2015-04-02 09:23:25 UTC