0
$\begingroup$

Rosanswers logo

EDIT I've worked out how to set the CMAKE flags and thus have been able to capture the link statement that fails. Its shown it at the bottom of this post.

I am doing an assignment at Uni whereby I need to build a package that incorporates code that was developed outside of ROS. I'm adding ROS functionality to it. I'm not bringing the source files into my project folder, but rather, including their normal locations in my CMakeLists.txt. (Don't want two versions floating around.)

I've now been able to make the original program run as a ROS Node using rosrun mypackage mypackage_node.

The problem I'm having is that as soon as I include a statement in my code that uses ROS functionality, the catkin_make build fails during linking with the following error:

CMakeFiles/gwbrb_node.dir/src/gwbrb.cpp.o: In function `GUMonitor::callback(guWb::wb_types, gsw_simple_message*)': /home/user/src/MPL/Gao/posix/guWbR/src/gwbrb/src/gwbrb.cpp:123: undefined reference to `ros::NodeHandle::NodeHandle(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&)' clang: error: linker command failed with exit code 1 (use -v to see invocation) 

I have included "ros/ros.h", and the statement that causes the error is ros::NodeHandle nForWNb; With this statement commented out, it works as stated above.

Because I suspected the ROS libraries were not being located, I decided to print the value of ${catkin_LIBRARIES} in my CMakeList.txt file, and have found that it evaluates to NULL. This is not right, since I am executing `source ~/ros_catkin_ws/install_isolated/setup.bash` when I open my shell.</strike> That is the wrong place to print its value... Now, when I print the value of ${catkin_LIBRARIES}, just before the target_link_libraries() clause, it holds the value:

/home/user/ros_catkin_ws/install_isolated/lib/libroscpp.so;/usr/lib/x86_64-linux-gnu/libboost_signals.so;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;/home/user/ros_catkin_ws/install_isolated/lib/librosconsole.so;/home/user/ros_catkin_ws/install_isolated/lib/librosconsole_log4cxx.so;/home/user/ros_catkin_ws/install_isolated/lib/librosconsole_backend_interface.so;/usr/lib/liblog4cxx.so;/usr/lib/x86_64-linux-gnu/libboost_regex.so;/home/user/ros_catkin_ws/install_isolated/lib/libxmlrpcpp.so;/home/user/ros_catkin_ws/install_isolated/lib/libroscpp_serialization.so;/home/user/ros_catkin_ws/install_isolated/lib/librostime.so;/usr/lib/x86_64-linux-gnu/libboost_date_time.so;/usr/lib/x86_64-linux-gnu/libboost_system.so;/usr/lib/x86_64-linux-gnu/libboost_thread.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/home/user/ros_catkin_ws/install_isolated/lib/libcpp_common.so;/home/user/ros_catkin_ws/install_isolated/lib/libconsole_bridge.so 

I think something in my CMakeLists.txt file is causing this problem, but I don't know where, or how to discover the problem. I've included my CMakeList.txt & package.xml listings below:

package.xml

... <buildtool_depend>catkin</buildtool_depend> <build_depend>roscpp</build_depend> <build_depend>rospy</build_depend> <build_depend>std_msgs</build_depend> <!-- <build_depend>ncurses</build_depend> --> <run_depend>roscpp</run_depend> <run_depend>rospy</run_depend> <run_depend>std_msgs</run_depend> <!-- <run_depend>ncurses</run_depend> --> ... 

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3) project(gwbrb) set(MPL_DIR $ENV{MPL_DIR}) #set(LOCAL_LINK ${MPL_DIR}/Gao/posix/gWbRb/src/gwbrb/src/build.host/) message(STATUS "MPL_DIR is ${MPL_DIR}") message(STATUS "ROS Link libraries @ ${catkin_LIBRARIES}") ## Find catkin macros and libraries ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) ## is used, also find other catkin packages find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs ) find_package(Threads REQUIRED COMPONENTS system) ## System dependencies are found with CMake's conventions # find_package(Boost REQUIRED COMPONENTS system) ## Needs clang++ find_program(CLANGPP clang++ HINTS /usr/local/bin /usr/bin /opt/local/bin) if(${CLANGPP} MATCHES "clang") set(CXX ${CLANGPP}) message(STATUS "CXX = ${CXX}") endif(${CLANGPP} MATCHES "clang") ## Needs clang find_program(CLANG clang HINTS /usr/local/bin /usr/bin /opt/local/bin) if(${CLANG} MATCHES "clang") set(CC ${CLANG}) message(STATUS "CC = ${CC}") endif(${CLANG} MATCHES "clang") ################################### ## catkin specific configuration ## ################################### ## The catkin_package macro generates cmake config files for your package ## Declare things to be passed to dependent projects ## INCLUDE_DIRS: uncomment this if you package contains header files ## LIBRARIES: libraries you create in this project that dependent projects also need ## CATKIN_DEPENDS: catkin_packages dependent projects also need ## DEPENDS: system dependencies of this project that dependent projects also need catkin_package( INCLUDE_DIRS ${MPL_DIR}/Gao/posix/gswb ${MPL_DIR}/Gao/Common # LIBRARIES CATKIN_DEPENDS roscpp rospy std_msgs DEPENDS system_lib ) ########### ## Build ## ########### set(CMAKE_C_FLAGS "-std=c99") set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++") set(CMAKE_SHARED_LINKER_FLAGS "-stdlib=libstdc++ -Wl,-rpath -Wl,/usr/local/lib") ## Specify additional locations of header files ## Your package locations should be listed before other locations # include_directories(include) include_directories( ${MPL_DIR}/Gao/posix/gswb ${MPL_DIR}/Gao/Common ${MPL_DIR}/Gao/posix/gswb/typeClassDefs ${catkin_INCLUDE_DIRS} ) ## Declare a cpp library add_library(gwbrb ${MPL_DIR}/Gao/posix/gswb/ggwbo.cpp ${MPL_DIR}/Gao/posix/gswb/gswb.c ${MPL_DIR}/Gao/posix/gswb/gtiwbo.cpp ${MPL_DIR}/Gao/Common/gu_util.cpp ${MPL_DIR}/Gao/posix/gswb/gwbg.cpp ${MPL_DIR}/Gao/posix/gswb/gwbp.cpp ${MPL_DIR}/Gao/posix/gswb/gwbtl_c_typestrings_generated.c ${MPL_DIR}/Gao/posix/gswb/Wb.cc ) ## Declare a cpp executable add_executable(gwbrb_node src/gwbrb.cpp ${MPL_DIR}/Gao/posix/gswb/ggwbo.cpp ${MPL_DIR}/Gao/posix/gswb/gswb.c ${MPL_DIR}/Gao/posix/gswb/gtiwbo.cpp ${MPL_DIR}/Gao/Common/gu_util.cpp ${MPL_DIR}/Gao/posix/gswb/gwbg.cpp ${MPL_DIR}/Gao/posix/gswb/gwbp.cpp ${MPL_DIR}/Gao/posix/gswb/gwbtl_c_typestrings_generated.c ${MPL_DIR}/Gao/posix/gswb/Wb.cc ) ## Add cmake target dependencies of the executable/library ## as an example, message headers may need to be generated before nodes #add_dependencies(gwbrb_node ${LOCAL_LINK}gwbp.o) ## Specify libraries to link a library or executable target against target_link_libraries(gwbrb_node ${catkin_LIBRARIES} gswb dispatch # rt # BlocksRuntime # pthread_workqueue # kqueue # pthread # ncurses ) 

Has anyone experienced this problem? What could be causing the linker to not know where the ROS libraries are at, and what can I do about it? (Set a variable manually?)

LINK STATEMENT and ERROR (I have given each argument, after the first series of switches, a line of its own to make it easier to read.)

Ubuntu clang version 3.4-1ubuntu1 (trunk) (based on LLVM 3.4) Target: x86_64-pc-linux-gnu Thread model: posix "/usr/bin/ld" -export-dynamic -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /home/user/src/MPL/Gao/posix/gWRb/devel/lib/gwrb/gwrb_node /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. -L/lib -L/usr/lib CMakeFiles/gwrb_node.dir/src/gwrb.cpp.o CMakeFiles/gwrb_node.dir/home/user/src/MPL/Gao/posix/gswb/ggwbo.cpp.o CMakeFiles/gwrb_node.dir/home/user/src/MPL/Gao/posix/gswb/gswb.c.o CMakeFiles/gwrb_node.dir/home/user/src/MPL/Gao/posix/gswb/gtiwbo.cpp.o CMakeFiles/gwrb_node.dir/home/user/src/MPL/Gao/Common/gu_util.cpp.o CMakeFiles/gwrb_node.dir/home/user/src/MPL/Gao/posix/gswb/gwbg.cpp.o CMakeFiles/gwrb_node.dir/home/user/src/MPL/Gao/posix/gswb/gwbp.cpp.o CMakeFiles/gwrb_node.dir/home/user/src/MPL/Gao/posix/gswb/gwbtl_c_typestrings_generated.c.o CMakeFiles/gwrb_node.dir/home/user/src/MPL/Gao/posix/gswb/Whiteboard.cc.o /home/user/ros_catkin_ws/install_isolated/lib/libroscpp.so -lboost_signals -lboost_filesystem /home/user/ros_catkin_ws/install_isolated/lib/librosconsole.so /home/user/ros_catkin_ws/install_isolated/lib/librosconsole_log4cxx.so /home/user/ros_catkin_ws/install_isolated/lib/librosconsole_backend_interface.so -llog4cxx -lboost_regex /home/user/ros_catkin_ws/install_isolated/lib/libxmlrpcpp.so /home/user/ros_catkin_ws/install_isolated/lib/libroscpp_serialization.so /home/user/ros_catkin_ws/install_isolated/lib/librostime.so -lboost_date_time -lboost_system -lboost_thread -lpthread /home/user/ros_catkin_ws/install_isolated/lib/libcpp_common.so /home/user/ros_catkin_ws/install_isolated/lib/libconsole_bridge.so -lgswb -ldispatch -rpath /home/user/ros_catkin_ws/install_isolated/lib -lc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o ERROR: CMakeFiles/gwrb_node.dir/src/gwrb.cpp.o: In function `GUMonitor::callback(guWb::wb_types, gsw_simple_message*)': /home/user/src/MPL/Gao/posix/gWRb/src/gwrb/src/gwrb.cpp:124: undefined reference to `ros::NodeHandle::NodeHandle(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&)' 

Cheers, Nap


Originally posted by Nap on ROS Answers with karma: 302 on 2014-04-22

Post score: 1


Original comments

Comment by Nap on 2014-04-23:
Since I've worked out how to use the '-v invocation', I am able to see the command given for each compile and link step. Using this info, I'm going to compare a working catkin package build with the build steps of the original project, and this build. Between the three, I hope I can figure it out.

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Uncomment the CATKIN_DEPENDS line in

catkin_package( INCLUDE_DIRS ${MPL_DIR}/Gao/posix/gswb ${MPL_DIR}/Gao/Common # LIBRARIES demo_webots_ros_driver # CATKIN_DEPENDS roscpp rospy std_msgs # DEPENDS system_lib ) 

Originally posted by BennyRe with karma: 2949 on 2014-04-22

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by Nap on 2014-04-22:
Benny, done but no change, same problem still persists.

Comment by BennyRe on 2014-04-23:
Sorry I went over the CMakeLists.txt documentation again and it seems I got the meaning of catkin_package wrong.

Comment by BennyRe on 2014-04-23:
As I have no experience with clang I can't help you anymore. The only thing that is strange to me is that the roscpp lib is searched in your catkin workspace and not in /opt/ros/ but I also have no experience with this install_isolated thing.

Comment by Nap on 2014-04-23:
Thanks Benny for trying. The path to /home/user/ros_catkin_ws/install_isolated/lib/libroscpp.so is correct. I built my ROS-Hydro from source, and installed it there.

$\endgroup$
0
$\begingroup$

Rosanswers logo

solved the problem, I was setting the wrong stdlib arguement in the CMAKE_CXX_FLAGS variable . set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++") needed to become set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libstdc++").


Originally posted by Nap with karma: 302 on 2014-04-24

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$