添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this is an unexpected error I got yesterday.

undefined reference to `pcl::search::Search<pcl::PointXYZ>::getName[abi:cxx11]() const' CMakeFiles/ros_exploration.dir/src/seg_fcn.cpp.o:(.data.rel.ro._ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE[_ZTVN3pcl6search6KdTreeINS_8PointXYZENS_11KdTreeFLANNIS2_N5flann9L2_SimpleIfEEEEEE]+0x20): undefined reference to `pcl::search::Search<pcl::PointXYZ>::getName[abi:cxx11]() const' CMakeFiles/ros_exploration.dir/src/seg_fcn.cpp.o:(.data.rel.ro._ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE[_ZTVN3pcl6search17OrganizedNeighborINS_8PointXYZEEE]+0x20): undefined reference to `pcl::search::Search<pcl::PointXYZ>::getName[abi:cxx11]() const'

here is my cmakelists

cmake_minimum_required(VERSION 2.4.6)
set(OpenCV_DIR "/usr/local/opencv-2.4.9/share/OpenCV")
include_directories("/usr/local/opencv-2.4.9/include")
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
find_package(Qt4 COMPONENTS QtCore QtGui)
find_package(OpenCV 2.4.9 REQUIRED)
find_package(Boost COMPONENTS system REQUIRED)
find_package(PCL 1.7 REQUIRED)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
rosbuild_init()
set(qt_srcs
	src/low_pass_filter.cpp
	src/pid_controller.cpp
	src/seg_fcn.cpp
	src/rrt.cpp
	src/potentialfield.cpp
	src/viewer.cpp
	src/listnerthr.cpp
	src/planning.cpp
	src/captureviewer.cpp
	src/frontier.cpp
	src/prm.cpp
set(qt_hdrs
	include/low_pass_filter.h
	include/pid_controller.h
	include/seg_fcn.h
	include/rrt.h
	include/potentialfield.h
	include/viewer.h
	include/listnerthr.h
	include/planning.h
	include/CreatBuffer.h
	include/captureviewer.h
	include/frontier.h
	include/prm.h
qt4_automoc(${qt_srcs})
QT4_WRAP_CPP(qt_moc_srcs ${qt_hdrs})
QT4_WRAP_UI(uis_h src/viewer.ui)
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
#set(ROS_BUILD_TYPE Debug)
#set(CMAKE_BUILD_TYPE Debug)
rosbuild_add_executable(ros_exploration src/main.cpp ${uis_h} ${qt_srcs} ${qt_hdrs} ${qt_moc_srcs})
target_link_libraries(ros_exploration 
${QT_LIBRARIES}  
${PCL_LIBRARIES}  
${Boost_LIBRARIES}
${OpenCV_LIBRARIES}
libvtkCommon.so
libvtkFiltering.so libvtkWidgets.so libvtksys.so libQVTK.so libvtkQtChart.so libvtkViews.so
libvtkRendering.so libvtkGraphics.so libvtkImaging.so libvtkIO.so libvtkDICOMParser.so libvtkmetaio.so
libvtkexoIIc.so libvtkftgl.so libvtkHybrid.so

any clues or suggestions would be appreciated.

The usual reason for linking errors:

  • not actually linking libraries. You're invoking target_link_libraries(ros_exploration ... ${PCL_LIBRARIES} ...) so that theory falls through.
  • You're instantiating a class with a type that is not instantiated during precompilation. In version 1.7.0, pcl::search::Search is precompiled with all point types, so that theory also falls through.
  • Someone forgot to implement getName, not the case since the method is implemented in the corresponding .hpp.
  • The only thing I see which flags my attention is this cxx11 abi message. Not sure exactly what you're doing here but I suspect it should not be a problem.

    Try first to manually read the symbols from the library and look for pcl::search::Search<pcl::PointXYZ>::getName() just to make sure it is there. In linux this can be achieved using

    $ readelf -Ws libpcl_search.so | c++filt | grep 'pcl::search::Search<pcl::PointXYZ>::getName'
     16645: 000000000039b652    18 FUNC    WEAK   DEFAULT   12 pcl::search::Search<pcl::PointXYZ>::getName() const
     14170: 000000000039b652    18 FUNC    WEAK   DEFAULT   12 pcl::search::Search<pcl::PointXYZ>::getName() const
    

    If it is there, then the last two options are excluded. It means linking is not happening properly.

    Edit: last case scenario we should consider symbol visibility problems, but let's cross that bridge once we reach it.

    I may had the same issue. That's why I document my observations here.

    Linker output

    CMakeFiles/octree-demo.dir/octree.cpp.o:(.data.rel.ro._ZTVN3pcl6search6OctreeINS_8PointXYZENS_6octree27OctreeContainerPointIndicesENS3_20OctreeContainerEmptyENS3_10OctreeBaseIS4_S5_EEEE[_ZTVN3pcl6search6OctreeINS_8PointXYZENS_6octree27OctreeContainerPointIndicesENS3_20OctreeContainerEmptyENS3_10OctreeBaseIS4_S5_EEEE]+0x20): undefined reference to `pcl::search::Search<pcl::PointXYZ>::getName[abi:cxx11]() const'
    CMakeFiles/octree-demo.dir/octree.cpp.o:(.data.rel.ro._ZTVN3pcl6search6SearchINS_8PointXYZEEE[_ZTVN3pcl6search6SearchINS_8PointXYZEEE]+0x20): undefined reference to `pcl::search::Search<pcl::PointXYZ>::getName[abi:cxx11]() const'
    

    Setup

  • Ubuntu Xenial (ubuntu:xenial Docker)
  • libpcl-1.7 (provided by libpcl-dev)
  • Clang 3.8.0 (provided by clang)
  • Interestingly, this only occurs when building with clang (see travis jobs for gcc and clang with the same build options)

    Using PCL_INSTANTIATE as proposed here 'solved it' (as in 'I have no idea what I am doing').

    For the sake of completeness: here is the output of @SergioRAgostinho 's suggested command:

    readelf -Ws /usr/lib/x86_64-linux-gnu/libpcl_search.so | c++filt | grep 'pcl::search::Search<pcl::PointXYZ>::getName'
      3326: 00000000000c5080     5 FUNC    WEAK   DEFAULT   11 pcl::search::Search<pcl::PointXYZ>::getName() const
    morrisfranken, jaymwong, PoplarTang, nickolai-voyage, Fla3inH0tCheet0s, a-price, pdaelm, kartikmadhira1, mfazampour, sco09, and 13 more reacted with thumbs up emoji MI-Hussain reacted with laugh emoji TixiaoShan, MI-Hussain, and AKC141096 reacted with hooray emoji SoftwareApe, PoplarTang, mfazampour, JakubHazik, narutojxl, TixiaoShan, and MI-Hussain reacted with heart emoji TixiaoShan, MI-Hussain, and adamanov reacted with rocket emoji All reactions

    @taketwo: You are completely right. Including <pcl/search/impl/search.hpp> is enough. Thank you for your feedback.

    It's effective for me.

    I had the same problem, #include <pcl/search/impl/search.hpp> solved the compiling problem. but at run time it gives this error:
    undefined symbol: _ZNK3pcl6search6SearchINS_11PointXYZRGBEE7getNameB5cxx11Ev

    Setting the -Wabi=11 flag to prevent ABI warnings has the side-effect of putting certain calls into the CXX11 ABI standard which causes link errors due to cxx11-suffixed symbols. This change prevents CXX11 whilst keeping the warnings suppressed.
    This is related to: PointCloudLibrary#2406

    I believe this problem comes from this line which was added to suppress ABI-related warnings. Unfortunately it means that certain functions are set to the CXX11 standard which results in a distinct function call signature so the build fails at the link stage.

    My solution was to add the following line somewhere towards the beginning of CMakeLists.txt:
    add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

    I've put this into a pull request.

    @taketwo: You are completely right. Including <pcl/search/impl/search.hpp> is enough. Thank you for your feedback.

    he saved my time and whole day effort. Thank you