1. 程式人生 > >Ubuntu16.04編譯VIORB過程中遇到的問題 尤其是rosbag的問題

Ubuntu16.04編譯VIORB過程中遇到的問題 尤其是rosbag的問題

下面的連結是非常非常有用的,很詳盡,筆芯博主。

https://blog.csdn.net/Amazingren/article/details/82357179 

尤其是解決了我關於rosbag報錯的問題,undefined reference to XXX 

看到這些報錯我也很頭大很生氣很生氣,以前跑得賊溜的程式碼也不能make了,打擊:

Scanning dependencies of target VIO
[ 66%] Building CXX object CMakeFiles/VIO.dir/src/MsgSync/MsgSynchronizer.cpp.o
[ 66%] Building CXX object CMakeFiles/VIO.dir/src/ros_vio.cc.o
[100%] Linking CXX executable ../VIO
CMakeFiles/VIO.dir/src/ros_vio.cc.o: In function `bool rosbag::Bag::readField<unsigned int>(std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > > const&, std::string const&, bool, unsigned int*) const':
ros_vio.cc:(.text._ZN3ros27SubscriptionCallbackHelperTIRKN5boost10shared_ptrIKN11sensor_msgs4Imu_ISaIvEEEEEvE11deserializeERKNS_43SubscriptionCallbackHelperDeserializeParamsE[_ZN3ros27SubscriptionCallbackHelperTIRKN5boost10shared_ptrIKN11sensor_msgs4Imu_ISaIvEEEEEvE11deserializeERKNS_43SubscriptionCallbackHelperDeserializeParamsE]+0x6f7): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'
CMakeFiles/VIO.dir/src/ros_vio.cc.o: In function `boost::shared_ptr<sensor_msgs::Imu_<std::allocator<void> > > rosbag::Bag::instantiateBuffer<sensor_msgs::Imu_<std::allocator<void> > >(rosbag::IndexEntry const&) const':
ag3Bag17instantiateBufferIN11sensor_msgs4Imu_ISaIvEEEEEN5boost10shared_ptrIT_EERKNS_10IndexEntryE[_ZNK6rosbag3Bag17instantiateBufferIN11sensor_msgs4Imu_ISaIvEEEEEN5boost10shared_ptrIT_EERKNS_10IndexEntryE]+0x3df): 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'
CMakeFiles/VIO.dir/src/ros_vio.cc.o: In function `boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > > rosbag::Bag::instantiateBuffer<sensor_msgs::Image_<std::allocator<void> > >(rosbag::IndexEntry const&) const':
ros_vio.cc:(.text._ZNK6rosbag3Bag17instantiateBufferIN11sensor_msgs6Image_ISaIvEEEEEN5boost10shared_ptrIT_EERKNS_10IndexEntryE[_ZNK6rosbag3Bag17instantiateBufferIN11sensor_msgs6Image_ISaIvEEEEEN5boost10shared_ptrIT_EERKNS_10IndexEntryE]+0x3df): more undefined references 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' follow
CMakeFiles/VIO.dir/src/ros_vio.cc.o: In function `main':
ros_vio.cc:(.text.startup+0x5f): undefined reference to `ros::init(int&, char**, std::string const&, unsigned int)'
ros_vio.cc:(.text.startup+0x216): 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&)'
collect2: error: ld returned 1 exit status
CMakeFiles/VIO.dir/build.make:268: recipe for target '../VIO' failed
make[2]: *** [../VIO] Error 1
CMakeFiles/Makefile2:163: recipe for target 'CMakeFiles/VIO.dir/all' failed
make[1]: *** [CMakeFiles/VIO.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

Launch file in Examples/ROS/ORB_VIO/launch.

以至於看到make到66就會內心顫抖,就知道卡死了。。。

之前ubuntu16.04的g++和gcc版本是5.4.0,為了配合matlab程式設計,將其降到啦4.9,導致了後來make不成功的問題,

將其版本升級:

sudo apt-get remove gcc

sudo apt-get install gcc

檢視gcc和g++版本可使用:

gcc -v

g++ -v

輸入g++的時候,系統會提示安裝g++的指令,複製貼上即可。

這之後又碰到新問題了:

Could NOT find CHOLMOD (missing:  CHOLMOD_INCLUDE_DIR CHOLMOD_LIBRARIES) 
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.

安裝相關依賴項就解決問題了:

sudo apt-get install libsuitesparse-dev

現在所有的程式碼都能正常執行啦~。~