Etimr
Etimr

Reputation: 51

undefined reference openscenegraph

I'm trying to compile a ROS OSG project from here https://github.com/uji-ros-pkg/visualization_osg and keep getting following error:

    CMakeFiles/osg_interactive_markers_demo.dir/examples/osg_interactive_markers_demo.cpp.o: In function `main':
/home/user/catkin_ws/src/visualization_osg/osg_interactive_markers/examples/osg_interactive_markers_demo.cpp:28: undefined reference to `osgViewer::View::addEventHandler(osgGA::EventHandler*)'
/home/user/catkin_ws/src/visualization_osg/osg_interactive_markers/examples/osg_interactive_markers_demo.cpp:29: undefined reference to `osgViewer::View::addEventHandler(osgGA::EventHandler*)'
/home/user/catkin_ws/devel/lib/libosg_utils.so: undefined reference to `osg::NodeVisitor::NodeVisitor(osg::NodeVisitor const&, osg::CopyOp const&)'
/home/user/catkin_ws/devel/lib/libosg_interactive_markers.so: undefined reference to `osg::Group::removeChild(osg::Node*)'
/home/user/catkin_ws/devel/lib/libosg_utils.so: undefined reference to `osg::NodeVisitor::apply(osg::Geometry&)'
/home/user/catkin_ws/devel/lib/libosg_interactive_markers.so: undefined reference to `osg::Group::getNumChildren() const'
/home/user/catkin_ws/devel/lib/libosg_utils.so: undefined reference to `osg::NodeVisitor::apply(osg::Drawable&)'

As I understand there should be a linking problem, but I couldn't find a way to fix it. My CMake file looks as followed:

cmake_minimum_required(VERSION 2.8.3)
project(osg_interactive_markers)

find_package(catkin REQUIRED COMPONENTS roscpp tf interactive_markers)

find_package(osg_utils REQUIRED)
find_package(osg_markers REQUIRED)
find_package(OpenSceneGraph REQUIRED COMPONENTS osgSim osgUtil osgDB osgFX osgGA osgTerrain osgViewer osgText osgWidget osgManipulator osg)

catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS
  roscpp
  tf
  interactive_markers
DEPENDS
  osg_markers
  osg_utils
  libopenscenegraph
)

include_directories(include ${catkin_INCLUDE_DIRS} ${osg_utils_INCLUDE_DIRS} ${osg_markers_INCLUDE_DIRS} ${OpenSceneGraph_INCLUDE_DIRS})
add_library(${PROJECT_NAME}
  src/interactive_marker_client.cpp
  src/interactive_marker_display.cpp
  src/interactive_marker.cpp
  src/interactive_marker_control.cpp
  src/draggers.cpp
)

target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES}  ${OSGUTILS_LIBRARIES} ${OSGMARKERS_LIBRARIES} -lGLU )

add_executable(osg_interactive_markers_demo examples/osg_interactive_markers_demo.cpp)
target_link_libraries(osg_interactive_markers_demo ${PROJECT_NAME} ${catkin_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES} ${OSGUTILS_LIBRARIES} ${OSGMARKERS_LIBRARIES} -lGLU )

add_dependencies(${PROJECT_NAME} ${catkin_EXPORTED_TARGETS})

configure_file(osgInteractiveMarkersConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/lib/${CMAKE_PROJECT_NAME}Config.cmake @ONLY)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib/${CMAKE_PROJECT_NAME}Config.cmake 
        DESTINATION share/${CMAKE_PROJECT_NAME} )

install(
TARGETS
osg_interactive_markers_demo 
${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
install(DIRECTORY include/${PROJECT_NAME}
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})

Any ideas what can be done here? I'm new to OSG and I really appreciate your help.

Upvotes: 1

Views: 2011

Answers (2)

Etimr
Etimr

Reputation: 51

Problem solved, the reason was wrong (double) installation of the OSG

Upvotes: 1

rickyviking
rickyviking

Reputation: 846

You're not targeting the correct OSG link libraries.

I cannot comment on the specific github project you mention, but in general if you're using the FindOSG.cmake module which comes with the osg distribution, you should invoke it with

FIND_PACKAGE(OSG REQUIRED)

and then link the specific osg libraries like

OSG_LIBRARY
OSGUTIL_LIBRARY
OSGGA_LIBRARY
etc...

there is no "global" OPENSCENEGRAPH_LIBRARIES symbol defined, see FindOSG.cmake

Upvotes: 0

Related Questions