ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Undefined reference to functions in header class? [closed]

asked 2014-07-24 14:51:27 -0500

mysteriousmonkey29 gravatar image

updated 2014-07-25 13:08:24 -0500

Hello, I'm currently attempting to convert a C++ driver demo program that came with a hardware system my boss purchased into a C++ ROS node that will do pretty much the same thing (except within ROS), which is to connect to a smart motor and laser scanner via USB and ethernet connections respectively, and then publish the scans continually while rotating the scanner back and forth (the original program saves the scans to a log file, and I will eventually change this to publishing ROS scan_msgs but have not gotten around to this yet). Right now I am running into some strange compiler errors that basically say "undefined reference to <every function="" from="" the="" classes="" in="" the="" imported="" header="" files="">". Here is the code/compiler errors:

CMakeLists: http://pastebin.com/Umi97hN5 (there are a couple other files in this project; I kept them in case their CMake stuff is screwing up this particular node. sweepLaserInterface is the one I'm talking about here) Node: http://pastebin.com/0AuteZeM (not yet modified from original except for the include statements because I moved the header and other cpp files into the include folder) Errors: http://pastebin.com/5zTxwGSm

Any ideas as to what could be going wrong? This program was working perfectly until I tried to repackage it as a ROS node.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by mysteriousmonkey29
close date 2014-07-25 15:21:17.762744

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-07-24 15:15:01 -0500

kmhallen gravatar image

You must link against the library that contains the code for those functions.

target_link_libraries(sweepLaserInterface_node ${catkin_LIBRARIES} some_library)

OR

Include the code for those functions in the executable.

add_executable(sweepLaserInterface_node src/sweepLaserInterface.cpp src/motorInterface.cpp)
edit flag offensive delete link more

Comments

This totally sounds right, so maybe I am misimplimenting this solution, but this didn't solve the problem. I tried the first way (with target_link_libraries), but couldn't get the path right (not sure where it starts looking), so moved on to the second method (add_executable). My CMakeLists.txt now reads: #sweepLaserInterface node add_executable(sweepLaserInterface_node src/sweepLaserInterface.cpp include/sweepLaserInterface/sickLMS115Interface.cpp include/sweepLaserInterface/motorInterface.cpp) target_link_libraries(sweepLaserInterface_node ${catkin_LIBRARIES}) , but I am getting similar (but I don't think exactly the same) errors: http://pastebin.com/KW4shySV

mysteriousmonkey29 gravatar image mysteriousmonkey29  ( 2014-07-24 15:58:44 -0500 )edit

#sweepLaserInterface node add_executable(sweepLaserInterface_node src/sweepLaserInterface.cpp include/sweepLaserInterface/sickLMS115Interface.cpp include/sweepLaserInterface/motorInterface.cpp) target_link_libraries(sweepLaserInterface_node ${catkin_LIBRARIES})

mysteriousmonkey29 gravatar image mysteriousmonkey29  ( 2014-07-24 15:59:17 -0500 )edit

Sorry, I guess you can't do the indenting thing in comments, so I recommented the CMakeLists contents for readability.

mysteriousmonkey29 gravatar image mysteriousmonkey29  ( 2014-07-24 16:00:52 -0500 )edit

please ask c++ questions on programming forums.

McMurdo gravatar image McMurdo  ( 2014-07-24 16:35:39 -0500 )edit

Ok, I will next time. When I try to add the libraries to the target_link_libaries line, however, I get the error: /usr/bin/ld: cannot find -linclude/sweepLaserInterface/sickLMS115Interface.cpp /usr/bin/ld: cannot find -linclude/sweepLaserInterface/motorInterface.cpp, or just -l<whatever path="" i="" put="" in="" front="" of="" the="" libraries="">. Do you know what I could be doing wrong here? What directory does the target link libraries command start its search in?

mysteriousmonkey29 gravatar image mysteriousmonkey29  ( 2014-07-24 16:48:18 -0500 )edit

you should link it against a shared object. Not the cpp source.

McMurdo gravatar image McMurdo  ( 2014-07-24 17:11:51 -0500 )edit

If you do not yet have the shared object/static object, then use method 2 from the answer.

McMurdo gravatar image McMurdo  ( 2014-07-24 17:15:22 -0500 )edit

I'm not sure what you mean by linking it against a shared object (what exactly that would look like), but, as I mentioned, I already tried method 2, and it did not solve the problem. In fact, I believe you originally responded to that with "you have to do both," which you have now deleted and thus thoroughly confused me.

mysteriousmonkey29 gravatar image mysteriousmonkey29  ( 2014-07-25 11:23:08 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-07-24 14:51:27 -0500

Seen: 3,890 times

Last updated: Jul 25 '14