laboshinl / loam_velodyne

Laser Odometry and Mapping (Loam) is a realtime method for state estimation and mapping using a 3D lidar.
http://wiki.ros.org/loam_velodyne
Other
1.71k stars 952 forks source link

Link error: undefined reference of ros::init(...), ros::NodeHandle(...) .... #101

Open wykxwyc opened 5 years ago

wykxwyc commented 5 years ago

================================= update on 2018-12-02

I finally figured out that my problem. And it was not accurately described in my title. It was because of the compiler that caused the undefined reference problem. And the solution can be found here. Hope this would be some help for others.

Thanks!

================================= I build the project, but there are many Link Errors that I can not fix. Can anyone provide some advice? Thanks very much!

And here is my build progress:

note: some Chinese translated into English: "在函数‘main’中": in the main function "未定义的引用": undefined reference "错误": error "返回 ": return "正在等待未完成的任务....": waiting for the tasks to be finished...

robot@robot:~/loam_ws$ catkin_make -DCMAKE_BUILD_TYPE=Release Base path: /home/robot/loam_ws Source space: /home/robot/loam_ws/src Build space: /home/robot/loam_ws/build Devel space: /home/robot/loam_ws/devel Install space: /home/robot/loam_ws/install

Running command: "cmake /home/robot/loam_ws/src -DCMAKE_BUILD_TYPE=Release -DCATKIN_DEVEL_PREFIX=/home/robot/loam_ws/devel -DCMAKE_INSTALL_PREFIX=/home/robot/loam_ws/install -G Unix Makefiles" in "/home/robot/loam_ws/build"

-- Using CATKIN_DEVEL_PREFIX: /home/robot/loam_ws/devel -- Using CMAKE_PREFIX_PATH: /home/robot/catkin/devel;/opt/ros/indigo -- This workspace overlays: /home/robot/catkin/devel;/opt/ros/indigo -- Using PYTHON_EXECUTABLE: /usr/bin/python -- Using Debian Python package layout -- Using empy: /usr/bin/empy -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/robot/loam_ws/build/test_results -- Found gtest sources under '/usr/src/gtest': gtests will be built -- Using Python nosetests: /usr/bin/nosetests-2.7 -- catkin 0.6.19 -- BUILD_SHARED_LIBS is on WARNING: Package name "LC" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. -- ~~~~~~~~~~~~~ -- ~~ traversing 1 packages in topological order: -- ~~ - loam_velodyne -- ~~~~~~~~~~~~~ -- +++ processing catkin package: 'loam_velodyne' -- ==> add_subdirectory(loam_velodyne) -- Using these message generators: gencpp;genlisp;genpy -- Boost version: 1.54.0 -- Found the following Boost libraries: -- system -- filesystem -- thread -- date_time -- iostreams -- serialization -- chrono -- atomic -- regex -- Checking for module 'openni-dev' -- No package 'openni-dev' found -- Checking for module 'openni-dev' -- No package 'openni-dev' found -- Checking for module 'openni-dev' -- No package 'openni-dev' found -- looking for PCL_COMMON -- looking for PCL_OCTREE -- looking for PCL_IO -- looking for PCL_KDTREE -- looking for PCL_SEARCH -- looking for PCL_SAMPLE_CONSENSUS -- looking for PCL_FILTERS -- looking for PCL_FEATURES -- looking for PCL_KEYPOINTS -- looking for PCL_GEOMETRY -- looking for PCL_SEGMENTATION -- looking for PCL_VISUALIZATION -- looking for PCL_OUTOFCORE -- looking for PCL_REGISTRATION -- looking for PCL_RECOGNITION -- looking for PCL_SURFACE -- looking for PCL_PEOPLE -- looking for PCL_TRACKING -- looking for PCL_APPS -- Configuring done -- Generating done -- Build files have been written to: /home/robot/loam_ws/build

Running command: "make -j4 -l4" in "/home/robot/loam_ws/build"

[ 5%] Building CXX object loam_velodyne/src/lib/CMakeFiles/loam.dir/ScanRegistration.cpp.o [ 11%] Building CXX object loam_velodyne/src/lib/CMakeFiles/loam.dir/LaserOdometry.cpp.o [ 16%] Building CXX object loam_velodyne/src/lib/CMakeFiles/loam.dir/BasicScanRegistration.cpp.o [ 22%] Building CXX object loam_velodyne/src/lib/CMakeFiles/loam.dir/MultiScanRegistration.cpp.o [ 27%] Building CXX object loam_velodyne/src/lib/CMakeFiles/loam.dir/BasicLaserOdometry.cpp.o [ 33%] Building CXX object loam_velodyne/src/lib/CMakeFiles/loam.dir/LaserMapping.cpp.o [ 38%] Building CXX object loam_velodyne/src/lib/CMakeFiles/loam.dir/BasicLaserMapping.cpp.o [ 44%] Building CXX object loam_velodyne/src/lib/CMakeFiles/loam.dir/TransformMaintenance.cpp.o [ 50%] Building CXX object loam_velodyne/src/lib/CMakeFiles/loam.dir/BasicTransformMaintenance.cpp.o [ 55%] Linking CXX shared library /home/robot/loam_ws/devel/lib/libloam.so [ 55%] Built target loam [ 61%] Building CXX object loam_velodyne/CMakeFiles/multiScanRegistration.dir/src/multi_scan_registration_node.cpp.o [ 66%] Building CXX object loam_velodyne/CMakeFiles/laserMapping.dir/src/laser_mapping_node.cpp.o [ 72%] Building CXX object loam_velodyne/CMakeFiles/transformMaintenance.dir/src/transform_maintenance_node.cpp.o [ 77%] Building CXX object loam_velodyne/CMakeFiles/laserOdometry.dir/src/laser_odometry_node.cpp.o [ 83%] Linking CXX executable /home/robot/loam_ws/devel/lib/loam_velodyne/transformMaintenance [ 88%] Linking CXX executable /home/robot/loam_ws/devel/lib/loam_velodyne/laserOdometry CMakeFiles/transformMaintenance.dir/src/transform_maintenance_node.cpp.o:在函数‘main’中: transform_maintenance_node.cpp:(.text.startup+0x34):对‘ros::init(int&, char, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, unsigned int)’未定义的引用 transform_maintenance_node.cpp:(.text.startup+0xc7):对‘ros::NodeHandle::NodeHandle(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::map<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::less<std::cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::cxx11::basic_string<char, std::char_traits, std::allocator > const, std::cxx11::basic_string<char, std::char_traits, std::allocator > > > > const&)’未定义的引用 transform_maintenance_node.cpp:(.text.startup+0x15a):对‘ros::NodeHandle::NodeHandle(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::map<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::less<std::cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::cxx11::basic_string<char, std::char_traits, std::allocator > const, std::cxx11::basic_string<char, std::char_traits, std::allocator > > > > const&)’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::hasParam(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::getParam(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, int&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::getParam(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, float&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::getParam(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::cxx11::basic_string<char, std::char_traits, std::allocator >&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::console::initializeLogLocation(ros::console::LogLocation*, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, ros::console::levels::Level)’未定义的引用 collect2: 错误:ld 返回 1 make[2]: * [/home/robot/loam_ws/devel/lib/loam_velodyne/transformMaintenance] 错误 1 make[1]: [loam_velodyne/CMakeFiles/transformMaintenance.dir/all] 错误 2 make[1]: 正在等待未完成的任务.... CMakeFiles/laserOdometry.dir/src/laser_odometry_node.cpp.o:在函数‘main’中: laser_odometry_node.cpp:(.text.startup+0x34):对‘ros::init(int&, char, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, unsigned int)’未定义的引用 laser_odometry_node.cpp:(.text.startup+0xc7):对‘ros::NodeHandle::NodeHandle(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::map<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::less<std::cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::cxx11::basic_string<char, std::char_traits, std::allocator > const, std::cxx11::basic_string<char, std::char_traits, std::allocator > > > > const&)’未定义的引用 laser_odometry_node.cpp:(.text.startup+0x15a):对‘ros::NodeHandle::NodeHandle(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::map<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::less<std::cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::cxx11::basic_string<char, std::char_traits, std::allocator > const, std::cxx11::basic_string<char, std::char_traits, std::allocator > > > > const&)’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::hasParam(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::getParam(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, int&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::getParam(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, float&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::getParam(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::cxx11::basic_string<char, std::char_traits, std::allocator >&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::console::initializeLogLocation(ros::console::LogLocation*, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, ros::console::levels::Level)’未定义的引用 collect2: 错误:ld 返回 1 make[2]: * [/home/robot/loam_ws/devel/lib/loam_velodyne/laserOdometry] 错误 1 make[1]: * [loam_velodyne/CMakeFiles/laserOdometry.dir/all] 错误 2 [ 94%] Linking CXX executable /home/robot/loam_ws/devel/lib/loam_velodyne/multiScanRegistration CMakeFiles/multiScanRegistration.dir/src/multi_scan_registration_node.cpp.o:在函数‘main’中: multi_scan_registration_node.cpp:(.text.startup+0x34):对‘ros::init(int&, char, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, unsigned int)’未定义的引用 multi_scan_registration_node.cpp:(.text.startup+0xc7):对‘ros::NodeHandle::NodeHandle(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::map<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::less<std::cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::cxx11::basic_string<char, std::char_traits, std::allocator > const, std::cxx11::basic_string<char, std::char_traits, std::allocator > > > > const&)’未定义的引用 multi_scan_registration_node.cpp:(.text.startup+0x15a):对‘ros::NodeHandle::NodeHandle(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::map<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::less<std::cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::cxx11::basic_string<char, std::char_traits, std::allocator > const, std::cxx11::basic_string<char, std::char_traits, std::allocator > > > > const&)’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::hasParam(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::getParam(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, int&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::getParam(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, float&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::getParam(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::cxx11::basic_string<char, std::char_traits, std::allocator >&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::console::initializeLogLocation(ros::console::LogLocation*, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, ros::console::levels::Level)’未定义的引用 collect2: 错误:ld 返回 1 make[2]: * [/home/robot/loam_ws/devel/lib/loam_velodyne/multiScanRegistration] 错误 1 make[1]: * [loam_velodyne/CMakeFiles/multiScanRegistration.dir/all] 错误 2 [100%] Linking CXX executable /home/robot/loam_ws/devel/lib/loam_velodyne/laserMapping CMakeFiles/laserMapping.dir/src/laser_mapping_node.cpp.o:在函数‘main’中: laser_mapping_node.cpp:(.text.startup+0x34):对‘ros::init(int&, char, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, unsigned int)’未定义的引用 laser_mapping_node.cpp:(.text.startup+0xc7):对‘ros::NodeHandle::NodeHandle(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::map<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::less<std::cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::cxx11::basic_string<char, std::char_traits, std::allocator > const, std::cxx11::basic_string<char, std::char_traits, std::allocator > > > > const&)’未定义的引用 laser_mapping_node.cpp:(.text.startup+0x15a):对‘ros::NodeHandle::NodeHandle(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::map<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::less<std::cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::cxx11::basic_string<char, std::char_traits, std::allocator > const, std::cxx11::basic_string<char, std::char_traits, std::allocator > > > > const&)’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::hasParam(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::getParam(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, int&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::getParam(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, float&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::NodeHandle::getParam(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::cxx11::basic_string<char, std::char_traits, std::allocator >&) const’未定义的引用 /home/robot/loam_ws/devel/lib/libloam.so:对‘ros::console::initializeLogLocation(ros::console::LogLocation*, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, ros::console::levels::Level)’未定义的引用 collect2: 错误:ld 返回 1 make[2]: * [/home/robot/loam_ws/devel/lib/loam_velodyne/laserMapping] 错误 1 make[1]: [loam_velodyne/CMakeFiles/laserMapping.dir/all] 错误 2 make: [all] 错误 2 Invoking "make -j4 -l4" failed robot@robot:~/loam_ws$

asmand001 commented 5 years ago

有人解决啦吗?

wykxwyc commented 5 years ago

有人解决啦吗?

把编译器改回gcc4.8(不知道你是不是和我一样将编译器改成了高版本)

asmand001 commented 5 years ago

谢谢啊,是的,我的4.9 后来还试了5 10 不知道你改成4.8解决了吗?

---Original--- From: "wykxwyc"notifications@github.com Date: Thu, Apr 18, 2019 19:53 PM To: "laboshinl/loam_velodyne"loam_velodyne@noreply.github.com; Cc: "asmand001"asmand@qq.com;"Comment"comment@noreply.github.com; Subject: Re: [laboshinl/loam_velodyne] Link error: undefined reference of ros::init(...), ros::NodeHandle(...) .... (#101)

有人解决啦吗?

把编译器改回gcc4.8(不知道你是不是和我一样将编译器改成了高版本)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

wykxwyc commented 5 years ago

是的,解决了。

在 2019-04-18 20:41:30,"asmand001" notifications@github.com 写道: 谢谢啊,是的,我的4.9 后来还试了5 10 不知道你改成4.8解决了吗?

---Original--- From: "wykxwyc"notifications@github.com Date: Thu, Apr 18, 2019 19:53 PM To: "laboshinl/loam_velodyne"loam_velodyne@noreply.github.com; Cc: "asmand001"asmand@qq.com;"Comment"comment@noreply.github.com; Subject: Re: [laboshinl/loam_velodyne] Link error: undefined reference of ros::init(...), ros::NodeHandle(...) .... (#101)

有人解决啦吗?

把编译器改回gcc4.8(不知道你是不是和我一样将编译器改成了高版本)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

smmmmi commented 4 years ago

sudo apt-get install gcc-5 g++-5 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10 sudo update-alternatives --config gcc choose selection number