ERROR: undifined reference to sensors
For a project I'm working on I needed to not use the default way of installing but instead I manually installed all of the dependencies in: https://github.com/osrf/homebrew-simulation/blob/master/gazebo6.rb
I tried making and installing it by:
cmake -DENABLE_TESTS_COMPILATION:BOOL=False ../gazebo
make -j4 install
But this causes the following errors as a result of the make command:
../gazebo/physics/libgazebo_physics.so.6.1.0: undefined reference to `gazebo::sensors::SensorManager::~SensorManager()'
../gazebo/physics/libgazebo_physics.so.6.1.0: undefined reference to `gazebo::sensors::get_sensor(std::string const&)'
../gazebo/physics/libgazebo_physics.so.6.1.0: undefined reference to `gazebo::sensors::Sensor::FillMsg(gazebo::msgs::Sensor&)'
../gazebo/physics/libgazebo_physics.so.6.1.0: undefined reference to `gazebo::sensors::SensorManager::SensorManager()'
../gazebo/physics/libgazebo_physics.so.6.1.0: undefined reference to `gazebo::sensors::create_sensor(boost::shared_ptr<sdf::Element>, std::string const&, std::string const&, unsigned int)'
../gazebo/physics/libgazebo_physics.so.6.1.0: undefined reference to `gazebo::sensors::SensorManager::ResetLastUpdateTimes()'
../gazebo/physics/libgazebo_physics.so.6.1.0: undefined reference to `gazebo::sensors::remove_sensor(std::string const&)'
../gazebo/physics/libgazebo_physics.so.6.1.0: undefined reference to `gazebo::sensors::SensorManager::SensorsInitialized()'
collect2: error: ld returned 1 exit status
make[2]: *** [tools/gz-6.1.0] Error 1
make[1]: *** [tools/CMakeFiles/gz.dir/all] Error 2
make: *** [all] Error 2
I'm pretty much new to linux and can't find why this linking goes wrong.
Asked by huub8 on 2015-11-09 13:10:53 UTC
Answers
-------------------Real Answer-------------------
I hit your error when I'm trying to use physics::World stuff. I got around it by adding
set_target_properties(target_name PROPERTIES LINK_FLAGS "-Wl,--no-as-needed")
to my CMakeLists, where target_name is the name I give the executable in add_executable(target_name path_to_cpp_file)
I found the set_target_properties stuff from a post here: https://bitbucket.org/osrf/gazebo/issues/1516/physics-classes-call-sensors-functions
-------------------Initial answer-------------------
Not sure if this will work, depending on your version of Gazebo, etc., but I'm on Gazebo 2.2, and had a similar error with gazebo::transport and gazebo::world stuff. I had to edit my CMakeLists to include the GAZEBO_..._DIRS stuff.
The "Compiling The PlugIn" section of this page helped a LOT: http://gazebosim.org/tutorials/?tut=plugins_hello_world
Things got better once I added the following to my CMakeLists:
find_package(gazebo REQUIRED)
include_directories(${GAZEBO_INCLUDE_DIRS})
link_directories(${GAZEBO_LIBRARY_DIRS})
list(APPEND CMAKE_CXX_FLAGS "${GAZEBO_CXX_FLAGS}")
target_link_libraries(hello_world ${GAZEBO_LIBRARIES})
Asked by ElizabethA on 2016-10-07 11:04:56 UTC
Comments
Add gazebo_sensors
to target_link_libraries
for your executable. The problem in detail is described in Issue #1516
Asked by plim on 2016-11-18 09:46:44 UTC
Comments