Problem building shared library using catkin for ros::init(...)

asked 2016-03-30 08:39:19 -0500

mpc_agro gravatar image

updated 2016-03-30 10:42:34 -0500

I am trying to build a shared c library that includes ros code. The intention is to build a Ros interface to the new co-simulation FMI standard. I have made c wrappers for the c++ code I intend to use and without the ros::init(...) function call it seems to work fine. I think my problem is the cmake file I have made since it seems to be missing ros::init()

So I have the following structure:

  • fmu2watertank.c --main libary file
  • roswrapper.h -- c wrapper file .h file
  • roswrapper.cpp -- c wrapper file .cpp file
  • rosclass.h -- header file for class contaning ros code
  • rosclass.cpp -- cpp file for class contaning ros code

I use the following cmake file to compile the code:

cmake_minimum_required(VERSION 2.8.3)
project (ros_fmu_interface)

find_package(catkin REQUIRED COMPONENTS roscpp std_msgs rosgraph_msgs)

set(INCLUDE_DIR src src/include src/include/templates)

add_definitions(-DLIBXML_STATIC -DFMI_COSIMULATION -DMODEL_IDENTIFIER='tank' -DMODEL_GUID='"{8c4e810f-3df3-4a00-8276-176fa3c9f001}"')

SET(GCC_COVERAGE_COMPILE_FLAGS "-fmessage-length=0")

add_library(tank SHARED src/fmu2watertank.c src/roswrapper.cpp src/rosclass.cpp)

add_dependencies(tank ${PROJECT_NAME} msgs_gencpp)


The code seems to compile fine :

-- Using CATKIN_DEVEL_PREFIX: /home/martin/ros_into/devel
-- Using CMAKE_PREFIX_PATH: /home/martin/ros_into/devel;/opt/ros/jade
-- This workspace overlays: /home/martin/ros_into/devel;/opt/ros/jade
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/martin/ros_into/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.16
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - ros_fmu_interface
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'ros_fmu_interface'
-- ==> add_subdirectory(agro_intelli/fmu_units/ros_fmu_interface)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/martin/ros_into/build
#### Running command: "make -j8 -l8" in "/home/martin/ros_into/build"
Scanning dependencies of target tank
[ 66%] [ 66%] [100%] Building CXX object agro_intelli/fmu_units/ros_fmu_interface/CMakeFiles/tank.dir/src/rosclass.cpp.o
Building CXX object agro_intelli/fmu_units/ros_fmu_interface/CMakeFiles/tank.dir/src/roswrapper.cpp.o
Building C object agro_intelli/fmu_units/ros_fmu_interface/CMakeFiles/tank.dir/src/fmu2watertank.c.o
/home/martin/ros_into/src/agro_intelli/fmu_units/ros_fmu_interface/src/fmu2watertank.c:11:0: warning: "MODEL_IDENTIFIER" redefined [enabled by default]
 #define MODEL_IDENTIFIER tank
<command-line>:0:0: note: this is the location of the previous definition
/home/martin/ros_into/src/agro_intelli/fmu_units/ros_fmu_interface/src/fmu2watertank.c:12:0: warning: "MODEL_GUID" redefined [enabled by default]
 #define MODEL_GUID "{8c4e810f-3df3-4a00-8276-176fa3c9f001}"
<command-line>:0:0: note: this is the location of the previous definition
/home/martin/ros_into/src/agro_intelli/fmu_units/ros_fmu_interface/src/rosclass.cpp: In member function ‘void rosClass::setup()’:
/home/martin/ros_into/src/agro_intelli/fmu_units/ros_fmu_interface/src/rosclass.cpp:9:31: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   char *argv[] = {"tank", NULL};
Linking CXX shared library /home/martin/ros_into/devel/lib/
[100%] Built target tank

But when I look into library file using nm I notice the following:

nm -D

                 U _ZN3ros4initERiPPcRKSsj
0000000000005038 W _ZN5boost3argILi1EEC1Ev
0000000000005038 W _ZN5boost3argILi1EEC2Ev ...
edit retag flag offensive close merge delete


You write you "think my problem is the cmake file I have made since it seems to be missing ros::init()", but you don't tell us what issue you've observed. Do you get unresolved symbol errors at library load time?

gvdhoorn gravatar image gvdhoorn  ( 2016-03-30 09:01:48 -0500 )edit

When I load the library It cannot find _ZN3ros4initERiPPcRKSsj. Based on testing this problem relates to the line ros::init(argc, argv, "fmu_interface"); from above. I am just unsure what is missing or needs to be changed in my cmake file or if it is even possible to attempt what I am doing.

mpc_agro gravatar image mpc_agro  ( 2016-03-30 09:30:56 -0500 )edit

Hi, Just curious if you got it to work - the link between FMI and ROS ... ?

avssrc01tamu gravatar image avssrc01tamu  ( 2016-09-15 13:08:16 -0500 )edit