Ask Your Question
1

undefined reference to everything

asked 2019-01-28 05:31:34 -0500

ipgvl gravatar image

updated 2019-02-04 01:08:11 -0500

Hi,

I have a package in my workspace that uses openCV and cv_bridge. I needed the cuda module of openCV, but it doesn't exist in the default openCV of ROS. I installed another version of openCV that included the cuda modules, I tried to link my workspace and my package to the new openCV and I had lots of errors like "undefined reference to 'cv_bridge::...' ", "undefined reference to 'ros::init::...' ", "undefined reference to 'rosbag::...' ". I tried to solve the problems but I wasn't able, so I tried to return to the default openCV (it worked fine with my package before I tried to use cuda, etc.), but it gives the same errors now. I have uninstalled and reinstalled ROS, deleted my workspace and the package and I have created them again, but I have the same errors. I have all the dependencies in the CMakeLists.txt.

________

EDIT

For more information, I have created now a new node with a loop that does nothing but ros::spinOnce(); loop_rate.sleep(); in a different package, and I have the same undefined reference to errors about ros::init(...) and ros::NodeHandle::NodeHandle(...).

________

EDIT 2

I have exported my package to another computer with ros and it does work, so I think it is a problem in my ros installation or something wrong in the configuration of the computer or ubuntu (maybe CMake, g++ or gcc?). Please does anyone know which could be the problem? Please I really need help!

________

These are some of the errors:

undefined reference to 'cv_bridge::toCvCopy(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&, std::string const&)'
undefined reference to 'ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'
undefined reference to 'ros::init(int&, char**, std::string const&, unsigned int)'
undefined reference to 'ros::NodeHandle::NodeHandle(std::string const&, std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > > const&)'
undefined reference to 'rosbag::Bag::open(std::string const&, unsigned int)'
undefined reference to 'rosbag::TypeQuery::TypeQuery(std::string const&)'
undefined reference to 'rosbag::MessageInstance::getTopic() const'
undefined reference to 'pcl_ros::transformPointCloud(std::string const&, sensor_msgs::PointCloud2_<std::allocator<void> > const&, sensor_msgs::PointCloud2_<std::allocator<void> >&, tf::TransformListener const&)'
undefined reference to 'pcl::PCDWriter::writeBinary(std::string const&, pcl::PCLPointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&)'
undefined reference to 'pcl::PCDWriter::writeASCII(std::string const&, pcl::PCLPointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&, int)'
undefined reference to 'rosbag::MessageInstance::getMD5Sum() const'
undefined reference to 'rosbag::Bag::readField(std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > > const&, std::string const&, bool, std::string&) const'
undefined reference to 'rosbag::Bag::readField(std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > > const&, std::string ...
(more)
edit retag flag offensive close merge delete

Comments

2

Which OpenCV version is found when you compile? You can check the version in CMakeCache.txt, grep "OpenCV_DIR" build/CMakeCache.txt. Make sure you require a specific version so that you find the one with your CUDA modules enabled.

VictorLamoine gravatar imageVictorLamoine ( 2019-01-28 09:06:15 -0500 )edit

Thank you for your reply. This is what I found there: //The directory containing a CMake configuration file for OpenCV. OpenCV_DIR:PATH=/opt/ros/kinetic/share/OpenCV-3.3.1-dev It is the default openCV. I'm not even sure if I need a specific version, but the default doesn't have anything about cuda.

ipgvl gravatar imageipgvl ( 2019-01-28 09:36:45 -0500 )edit

If you need CUDA then you need to compile/install your own version of OpenCV. Then you need to specify to CMake which version of OpenCV you want to use. Either by setting the find_package to a specific version.

VictorLamoine gravatar imageVictorLamoine ( 2019-01-28 16:29:38 -0500 )edit

or by specifying the OpenCV path when calling catkin_make; eg: catkin_make -DOpenCV_DIR=/usr/local/opencv_install_path . You should also tweak your CMake file to make sure that the version you have found does have CUDA: https://tinyurl.com/ya4drp8a

VictorLamoine gravatar imageVictorLamoine ( 2019-01-28 16:30:46 -0500 )edit

I know, and that's why I installed another version of OpenCV that had CUDA, and I called catkin_make -DOpenCV_DIR=... , but since I did it I have those undefined reference to errors, and I don't know why. I did a catkin_make clean and now I use the default OpenCV again, but the errors persist.

ipgvl gravatar imageipgvl ( 2019-01-29 01:08:10 -0500 )edit

So I don't know if I have changed something important and now my package doesn't find the ros::init for example, and that's my main problem now.

ipgvl gravatar imageipgvl ( 2019-01-29 01:09:39 -0500 )edit

For more information, I have created now a new node with a loop that does nothing but ros::spinOnce(); loop_rate.sleep(); in a different package, and I have the same undefined reference to errors about ros::init(...) and ros::NodeHandle::NodeHandle(...)

ipgvl gravatar imageipgvl ( 2019-01-29 01:29:01 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-02-04 08:25:59 -0500

ipgvl gravatar image

updated 2019-02-04 09:36:03 -0500

I did lots of things to fix these errors so I'm not sure which of them did, but I think it was one of these:

  1. (I think it was what solved the problem) Uninstalling and reinstalling gcc and g++ to a specific version (in my case I had 4.8, 4.9 and 5.4 installed, so I uninstalled all and reinstalled 5.4.0 for both).
  2. Doing this: export CC=/usr/local/bin/gcc export CXX=/usr/local/bin/g++ or run catkin_make like: CXX=g++5 CC=gcc5 catkin_make. Like @gvdhoorn said, this should not be necessary, so 1. solved my problem

It was important to delete the build and devel folders, and then the catkin_make worked.

EDIT For more information, in this answer https://answers.ros.org/question/291910/linking-problem-with-catkin_libraries/ someone gave me the clue: "it looks like all of the unresolved symbols involve std::string, which changed between gcc 4.9 and gcc 5". I think that I had a problem because I had g++ and gcc of some versions at the same time and I wasn't using the right version, like I said below. I uninstalled the "bad" version but probably there is another way to fix it.

edit flag offensive delete link more

Comments

1

As I wrote in #q314609: export CC=.. and export CXX=.. should not be necessary. It's also strange to export those and then still prefix CC and CXX in a call to catkin_make.

Also: compilers in /usr/local is not a standard system setup (apt does not install compilers there).

gvdhoorn gravatar imagegvdhoorn ( 2019-02-04 08:28:53 -0500 )edit

I followed this answer: https://stackoverflow.com/questions/17275348/how-to-specify-new-gcc-path-for-cmake, that's why I used the export CC=..., but like you said probably it wasn't necessary.

ipgvl gravatar imageipgvl ( 2019-02-04 08:46:36 -0500 )edit

Even the export should not be necessary. If it is, then something is still not right.

gvdhoorn gravatar imagegvdhoorn ( 2019-02-04 08:47:53 -0500 )edit

Otherwise, I went to /usr/local when I did the export... because I wanted to know if the compiler was there and it was, but I don't know why. It was already there when I searched for it.

ipgvl gravatar imageipgvl ( 2019-02-04 08:48:46 -0500 )edit

Yes, that's why I put that I think the problem was solved because of the reinstallation. I suppose that I had a problem because I had g++ and gcc of some versions at the same time and I wasn't using the right version. I uninstalled the "bad" version but probably there is another way to fix it.

ipgvl gravatar imageipgvl ( 2019-02-04 08:52:10 -0500 )edit

Should I do something with the export ... now to return to the original state? Or should I not to touch anything more? Sorry for all, I am new in these things and I have been a week trying to solve it, and no one answered me until you, so I tried all I found on the internet.

ipgvl gravatar imageipgvl ( 2019-02-04 08:55:39 -0500 )edit

I'm happy to continue this, but please do so in #q314609. This is not the place, as it deals with a related problem / effect.

gvdhoorn gravatar imagegvdhoorn ( 2019-02-04 08:58:41 -0500 )edit

Ok, thank you.

ipgvl gravatar imageipgvl ( 2019-02-04 09:10:28 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-01-28 05:31:34 -0500

Seen: 342 times

Last updated: Feb 04