agile_grasp icon indicating copy to clipboard operation
agile_grasp copied to clipboard

How to solve undefined reference to `pcl::search::Search<pcl::PointXYZ>::Search?

Open b2220333 opened this issue 9 years ago • 9 comments

I use ubuntu 12.04 64bits with ROS Hydro.

I run: sudo apt-get install liblapack-dev git clone https://github.com/atenpas/agile_grasp.git -b hydro rospack profile

when I catkin_make, it shows errors:

... [ 74%] Built target handle_search Scanning dependencies of target localization CMakeFiles/test_taubin_fitting.dir/src/tests/test_taubin.cpp.o: In function main': test_taubin.cpp:(.text.startup+0x16b): undefined reference topcl::search::Searchpcl::PointXYZ::Search(std::basic_string<char, std::char_traits, std::allocator > const&, bool)' CMakeFiles/test_taubin_fitting.dir/src/tests/test_taubin.cpp.o:(.rodata._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[vtable for pcl::search::OrganizedNeighborpcl::PointXYZ]+0x30): undefined reference to pcl::search::Search<pcl::PointXYZ>::getSortedResults()' CMakeFiles/test_taubin_fitting.dir/src/tests/test_taubin.cpp.o:(.rodata._ZTVN3pcl6search6SearchINS_8PointXYZEEE[vtable for pcl::search::Search<pcl::PointXYZ>]+0x30): undefined reference topcl::search::Searchpcl::PointXYZ::getSortedResults()' collect2: ld returned 1 exit status make[2]: *** [/home/ira/code/ros_hydro/devel/lib/agile_grasp/test_taubin_fitting] Error 1 make[1]: *** [download/agile_grasp/CMakeFiles/test_taubin_fitting.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... CMakeFiles/hands_test.dir/src/tests/hands_test.cpp.o: In function main': hands_test.cpp:(.text.startup+0x16b): undefined reference topcl::search::Searchpcl::PointXYZ::Search(std::basic_string<char, std::char_traits, std::allocator > const&, bool)' CMakeFiles/hands_test.dir/src/tests/hands_test.cpp.o:(.rodata._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[vtable for pcl::search::OrganizedNeighborpcl::PointXYZ]+0x30): undefined reference to pcl::search::Search<pcl::PointXYZ>::getSortedResults()' CMakeFiles/hands_test.dir/src/tests/hands_test.cpp.o:(.rodata._ZTVN3pcl6search6SearchINS_8PointXYZEEE[vtable for pcl::search::Search<pcl::PointXYZ>]+0x30): undefined reference topcl::search::Searchpcl::PointXYZ::getSortedResults()' collect2: ld returned 1 exit status make[2]: *** [/home/ira/code/ros_hydro/devel/lib/agile_grasp/hands_test] Error 1 make[1]: *** [download/agile_grasp/CMakeFiles/hands_test.dir/all] Error 2 [ 76%] Building CXX object download/agile_grasp/CMakeFiles/localization.dir/src/agile_grasp/localization.cpp.o Linking CXX shared library /home/ira/code/ros_hydro/devel/lib/liblocalization.so [ 76%] Built target localization make: *** [all] Error 2 Invoking "make" failed ira@ira:~/code/ros_hydro$

It's looks like the PCL linking problem. How to solve it? Thank you~

b2220333 avatar Jun 12 '15 14:06 b2220333

I'm not sure what the problem is because test_taubin.cpp has an include for pcl/search/organized.h, and the file is linked to PCL libraries (https://github.com/atenpas/agile_grasp/blob/hydro/CMakeLists.txt#L142).

Do you have different versions of PCL installed?

atenpas avatar Jun 13 '15 07:06 atenpas

I do not remember I install the version of PCL without ROS or not. What should I do?

b2220333 avatar Jun 13 '15 08:06 b2220333

You could remove all lines related to test_taubin.cpp from CMakeLists.txt. It's just a test file - it's not required to run the ROS nodes.

atenpas avatar Jun 13 '15 08:06 atenpas

After I comment: #add_executable(test_taubin_fitting src/tests/test_taubin.cpp) #target_link_libraries(test_taubin_fitting quadric ${PCL_LIBRARIES})

And I compile again, it shows: [ 83%] Built target hand_search Linking CXX executable /home/sam/code/ros_hydro/devel/lib/agile_grasp/hands_test [ 85%] Built target handle_search [ 87%] Built target localization Linking CXX executable /home/sam/code/ros_hydro/devel/lib/agile_grasp/antipodal_test Linking CXX executable /home/sam/code/ros_hydro/devel/lib/agile_grasp/learning_test [ 88%] Built target grasp_localizer Linking CXX executable /home/sam/code/ros_hydro/devel/lib/agile_grasp/test_local_axes CMakeFiles/hands_test.dir/src/tests/hands_test.cpp.o: In function main': hands_test.cpp:(.text.startup+0x157): undefined reference topcl::search::Searchpcl::PointXYZ::Search(std::string const&, bool)' CMakeFiles/hands_test.dir/src/tests/hands_test.cpp.o:(.rodata._ZTVN3pcl6search6SearchINS_8PointXYZEEE[_ZTVN3pcl6search6SearchINS_8PointXYZEEE]+0x30): undefined reference to pcl::search::Search<pcl::PointXYZ>::getSortedResults()' CMakeFiles/hands_test.dir/src/tests/hands_test.cpp.o:(.rodata._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x30): undefined reference topcl::search::Searchpcl::PointXYZ::getSortedResults()' collect2: error: ld returned 1 exit status make[2]: *** [/home/sam/code/ros_hydro/devel/lib/agile_grasp/hands_test] Error 1 make[1]: *** [download/agile_grasp/CMakeFiles/hands_test.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference to pcl::PCLBase<pcl::PointXYZ>::setIndices(boost::shared_ptr<std::vector<int, std::allocator<int> > const> const&)' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference topcl::visualization::PCLVisualizer::wasStopped() const' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference to pcl::visualization::PCLVisualizer::close()' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference topcl::visualization::PointCloudGeometryHandlerXYZpcl::PointNormal::PointCloudGeometryHandlerXYZ(boost::shared_ptrpcl::PointCloud<pcl::PointNormal const> const&)' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference to pcl::visualization::PCLVisualizer::setPosition(int, int)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::PCLBasepcl::PointXYZ::setIndices(boost::shared_ptr<std::vector<int, std::allocator > > const&)' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference to pcl::visualization::PointCloudGeometryHandlerXYZ<pcl::PointNormal>::getGeometry(vtkSmartPointer<vtkPoints>&) const' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::PCDReader::read(std::string const&, pcl::PCLPointCloud2&, Eigen::Matrix<float, 4, 1, 0, 4, 1>&, Eigen::Quaternion<float, 0>&, int&, int)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference to pcl::PCLBase<pcl::PointXYZ>::setIndices(boost::shared_ptr<pcl::PointIndices const> const&)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::PCLBasepcl::PointXYZ::PCLBase()' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference to pcl::visualization::PCLVisualizer::setSize(int, int)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::SACSegmentationpcl::PointXYZ::segment(pcl::PointIndices&, pcl::ModelCoefficients&)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference to pcl::PCLBase<pcl::PointXYZ>::setIndices(unsigned long, unsigned long, unsigned long, unsigned long)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::PCLBasepcl::PointXYZ::deinitCompute()' collect2: error: ld returned 1 exit status make[2]: *** [/home/sam/code/ros_hydro/devel/lib/agile_grasp/test_local_axes] Error 1 make[1]: *** [download/agile_grasp/CMakeFiles/test_local_axes.dir/all] Error 2 /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference to pcl::PCLBase<pcl::PointXYZ>::setIndices(boost::shared_ptr<std::vector<int, std::allocator<int> > const> const&)' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference topcl::visualization::PCLVisualizer::wasStopped() const' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference to pcl::visualization::PCLVisualizer::close()' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference topcl::visualization::PointCloudGeometryHandlerXYZpcl::PointNormal::PointCloudGeometryHandlerXYZ(boost::shared_ptrpcl::PointCloud<pcl::PointNormal const> const&)' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference to pcl::visualization::PCLVisualizer::setPosition(int, int)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::PCLBasepcl::PointXYZ::setIndices(boost::shared_ptr<std::vector<int, std::allocator > > const&)' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference to pcl::visualization::PointCloudGeometryHandlerXYZ<pcl::PointNormal>::getGeometry(vtkSmartPointer<vtkPoints>&) const' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::PCDReader::read(std::string const&, pcl::PCLPointCloud2&, Eigen::Matrix<float, 4, 1, 0, 4, 1>&, Eigen::Quaternion<float, 0>&, int&, int)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference to pcl::PCLBase<pcl::PointXYZ>::setIndices(boost::shared_ptr<pcl::PointIndices const> const&)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::PCLBasepcl::PointXYZ::PCLBase()' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference to pcl::visualization::PCLVisualizer::setSize(int, int)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::SACSegmentationpcl::PointXYZ::segment(pcl::PointIndices&, pcl::ModelCoefficients&)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference to pcl::PCLBase<pcl::PointXYZ>::setIndices(unsigned long, unsigned long, unsigned long, unsigned long)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::PCLBasepcl::PointXYZ::deinitCompute()' collect2: error: ld returned 1 exit status make[2]: *** [/home/sam/code/ros_hydro/devel/lib/agile_grasp/antipodal_test] Error 1 make[1]: *** [download/agile_grasp/CMakeFiles/antipodal_test.dir/all] Error 2 /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference to pcl::PCLBase<pcl::PointXYZ>::setIndices(boost::shared_ptr<std::vector<int, std::allocator<int> > const> const&)' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference topcl::visualization::PCLVisualizer::wasStopped() const' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference to pcl::visualization::PCLVisualizer::close()' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference topcl::visualization::PointCloudGeometryHandlerXYZpcl::PointNormal::PointCloudGeometryHandlerXYZ(boost::shared_ptrpcl::PointCloud<pcl::PointNormal const> const&)' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference to pcl::visualization::PCLVisualizer::setPosition(int, int)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::PCLBasepcl::PointXYZ::setIndices(boost::shared_ptr<std::vector<int, std::allocator > > const&)' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference to pcl::visualization::PointCloudGeometryHandlerXYZ<pcl::PointNormal>::getGeometry(vtkSmartPointer<vtkPoints>&) const' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::PCDReader::read(std::string const&, pcl::PCLPointCloud2&, Eigen::Matrix<float, 4, 1, 0, 4, 1>&, Eigen::Quaternion<float, 0>&, int&, int)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference to pcl::PCLBase<pcl::PointXYZ>::setIndices(boost::shared_ptr<pcl::PointIndices const> const&)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::PCLBasepcl::PointXYZ::PCLBase()' /home/sam/code/ros_hydro/devel/lib/libhandle_search.so: undefined reference to pcl::visualization::PCLVisualizer::setSize(int, int)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::SACSegmentationpcl::PointXYZ::segment(pcl::PointIndices&, pcl::ModelCoefficients&)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference to pcl::PCLBase<pcl::PointXYZ>::setIndices(unsigned long, unsigned long, unsigned long, unsigned long)' /home/sam/code/ros_hydro/devel/lib/liblocalization.so: undefined reference topcl::PCLBasepcl::PointXYZ::deinitCompute()' collect2: error: ld returned 1 exit status make[2]: *** [/home/sam/code/ros_hydro/devel/lib/agile_grasp/learning_test] Error 1 make[1]: *** [download/agile_grasp/CMakeFiles/learning_test.dir/all] Error 2 make: *** [all] Error 2 Invoking "make" failed sam@sam:~/code/ros_hydro$

b2220333 avatar Jun 13 '15 08:06 b2220333

Any solutions yet?

adityadhawale avatar Dec 12 '15 20:12 adityadhawale

My solution was cmake clean and rebuild. Don't understand why.

ydawei avatar Feb 06 '17 20:02 ydawei

add this to CMakeLists.txt

find_package (PCL 1.8 REQUIRED)

set(PCL_INCLUDE_DIRS /usr/local/include/pcl-1.8)  #指定pcl1.8路径

include_directories( ... ${PCL_INCLUDE_DIRS})

target_link_libraries( ... ${PCL_LIBRARIES})

qixuxiang avatar Mar 11 '18 00:03 qixuxiang

My problem is solved after qixuxiang suggestions, Now CMakeLists.txt look like:

cmake_minimum_required (VERSION 3.5.1)
project (icp)
find_package (PCL 1.7 REQUIRED)


set(PCL_INCLUDE_DIRS /usr/local/include/pcl-1.7 /usr/include/eigen3/)

include_directories(${PCL_INCLUDE_DIRS})

add_executable(pcl_test pcl_test.cpp)
target_link_libraries(pcl_test ${PCL_LIBRARIES})

UditSinghParihar avatar Sep 13 '18 10:09 UditSinghParihar

Including <pcl/search/impl/search.hpp> on top of your code. Good luck!

PoplarTang avatar Sep 24 '19 03:09 PoplarTang