Possible Linking conflict with ROS and json_spirit

asked 2014-07-07 15:24:43 -0500

DraconicDon gravatar image

updated 2014-07-08 01:36:51 -0500

gvdhoorn gravatar image

OS: Ubuntu 12.04 64-bit

ROS version: Hydro

GCC version: 4.6.3

I've been having getting some nasty linking errors when trying to use both json_reader and ros subscriber nodes. I have boiled the problem in the program to the code below. Simply commenting out the subscriber assignment or the json_spirit:: read call the program will build fine, it is only when both are compiled that I get the error at the bottom of this post. As far as I could find, it seems like it might be an inheritance problem with both json_spirit_reader and ROS both having some non virtual dependency that causes some sort of conflict. I could be wrong.

int main(int argc, char* argv[]) 
{
    ros::init(argc, argv, "test_node");
    ros::NodeHandle n;
    ros::Subscriber sub ;
    sub = n.subscribe("message", 3, callback);

    ifstream foo;

    json_spirit::Value bar;

    json_spirit::read(foo, bar);
}

Linker error:

`.text._ZN5boost16exception_detail19error_info_injectorINS_17bad_function_callEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_17bad_function_callEED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<boost::bad_function_call>::~error_info_injector()]' of /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libjson_spirit.a(json_spirit_reader.cpp.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_17bad_function_callEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_17bad_function_callEED5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libjson_spirit.a(json_spirit_reader.cpp.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_function_call> >::~clone_impl()]' of /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libjson_spirit.a(json_spirit_reader.cpp.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEED5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libjson_spirit.a(json_spirit_reader.cpp.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_function_call> >::~clone_impl()]' of /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libjson_spirit.a(json_spirit_reader.cpp.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_17bad_function_callEEEED5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libjson_spirit.a(json_spirit_reader.cpp.o)
collect2: ld returned 1 exit status

Edit: Full code and cmake text

Code:

#include "ros/ros.h"
#include "fstream"
#include "json_spirit.h"
#include "std_msgs/String.h"

using namespace std;

void callback(const std_msgs::String::ConstPtr& msg)
{

}

int main(int argc, char* argv[]) {

    ros::init(argc, argv, "test_node");
    ros::NodeHandle n;
    ros::Subscriber sub ;
    sub = n.subscribe("message", 3, callback);

    ifstream foo;

    json_spirit::Value bar;

    json_spirit::read(foo, bar);
}

cmake:

find_package(catkin REQUIRED COMPONENTS
  roscpp
)

add_executable(json_test src/json_test.cpp)
#add_dependencies(json_test ${catkin_EXPORTED_TARGETS})
add_dependencies(json_test boost_program_options ${catkin_EXPORTED_TARGETS} zanni_generate_messages )
target_link_libraries(json_test 
    json_spirit
    ${catkin_LIBRARIES}
)
edit retag flag offensive close merge delete

Comments

I'd recommend posting the full C++ file (including header includes) and the CMakeLists.txt so that someone can reproduce this.

fergs gravatar image fergs  ( 2014-07-07 15:37:35 -0500 )edit

Question edited to add the requested information.

DraconicDon gravatar image DraconicDon  ( 2014-07-07 17:12:24 -0500 )edit