单独编译PCL的kdtree模块报错“undefined reference to”

我打算使用gdb调试pcl的kdtree教程(kdtree_search.cpp)。由于pcl经过预编译,将kdtree模块编译成动态链接库。使用gdb无法进入动态链接库进行调试!

因此将kdtree模块(主要为kdtree_flann.h和kdtree_flann.hpp)的相关代码抽取出来,单独编译。代码包的树状图如下所示,

上图可见,kdtree模块的依赖了这么多文件,可见pcl的代码抽象程度,重用性做得非常好。

附上CMakeLists.txt,

cmake_minimum_required(VERSION 2.8.3)
project(kdtree_learn)

set(CMAKE_BUILD_TYPE "DEBUG")

add_definitions(-std=c++11)

find_package(PkgConfig REQUIRED)
pkg_check_modules(FLANN REQUIRED)

include_directories(
    "/usr/include/eigen3"
    "/home/gordon/kdtree_learn/include/"
    )

add_executable(${PROJECT_NAME} kdtree_search.cpp)

运行make进行编译,报错如下,

CMakeFiles/kdtree_learn.dir/kdtree_search.cpp.o: In function `main‘:
/home/gordon/kdtree_learn/kdtree_search.cpp:27: undefined reference to `pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::KdTreeFLANN(bool)‘
/home/gordon/kdtree_learn/kdtree_search.cpp:29: undefined reference to `pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::setInputCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> const> const&, boost::shared_ptr<std::vector<int, std::allocator<int> > const> const&)‘
/home/gordon/kdtree_learn/kdtree_search.cpp:49: undefined reference to `pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::nearestKSearch(pcl::PointXYZ const&, int, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&) const‘
/home/gordon/kdtree_learn/kdtree_search.cpp:71: undefined reference to `pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::radiusSearch(pcl::PointXYZ const&, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const‘
CMakeFiles/kdtree_learn.dir/kdtree_search.cpp.o: In function `pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::~KdTreeFLANN()‘:
/home/gordon/kdtree_learn/include/pcl/kdtree/kdtree_flann.h:140: undefined reference to `pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::cleanup()‘
CMakeFiles/kdtree_learn.dir/kdtree_search.cpp.o:(.rodata._ZTVN3pcl11KdTreeFLANNINS_8PointXYZEN5flann9L2_SimpleIfEEEE[_ZTVN3pcl11KdTreeFLANNINS_8PointXYZEN5flann9L2_SimpleIfEEEE]+0x10): undefined reference to `pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::setInputCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> const> const&, boost::shared_ptr<std::vector<int, std::allocator<int> > const> const&)‘
CMakeFiles/kdtree_learn.dir/kdtree_search.cpp.o:(.rodata._ZTVN3pcl11KdTreeFLANNINS_8PointXYZEN5flann9L2_SimpleIfEEEE[_ZTVN3pcl11KdTreeFLANNINS_8PointXYZEN5flann9L2_SimpleIfEEEE]+0x28): undefined reference to `pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::nearestKSearch(pcl::PointXYZ const&, int, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&) const‘
CMakeFiles/kdtree_learn.dir/kdtree_search.cpp.o:(.rodata._ZTVN3pcl11KdTreeFLANNINS_8PointXYZEN5flann9L2_SimpleIfEEEE[_ZTVN3pcl11KdTreeFLANNINS_8PointXYZEN5flann9L2_SimpleIfEEEE]+0x40): undefined reference to `pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::radiusSearch(pcl::PointXYZ const&, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const‘
CMakeFiles/kdtree_learn.dir/kdtree_search.cpp.o:(.rodata._ZTVN3pcl11KdTreeFLANNINS_8PointXYZEN5flann9L2_SimpleIfEEEE[_ZTVN3pcl11KdTreeFLANNINS_8PointXYZEN5flann9L2_SimpleIfEEEE]+0x58): undefined reference to `pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::setEpsilon(float)‘
collect2: error: ld returned 1 exit status

这个报错最头疼的地方在于,明明所有文件都已到齐,然而就是 undefined reference to ‘......‘。

经过一番排查,发现问题出在  kdtree_flann.h 中的一小段预编译代码,

#ifdef PCL_NO_PRECOMPILE
#include <pcl/kdtree/impl/kdtree_flann.hpp>
#endif

它的意思是:如果定义了宏,则表示这份代码不进行预编译,那么要添加 kdtree_flann.hpp 。

kdtree_flann.h 声明了 KdTreeFLANN 类,kdtree_flann.hpp 定义了类内的成员实现。

由于我把这部分代码抽离出来单独编译,也即是没有预编译,所以没有添加特定路径下的 kdtree_flann.hpp ,进而出现上述报错。

解决方案:

在 kdtree_flann.h 中添加  #define PCL_NO_PRECOMPILE  。搞定!

原文地址:https://www.cnblogs.com/gdut-gordon/p/12289653.html

时间: 2024-11-09 19:06:16

单独编译PCL的kdtree模块报错“undefined reference to”的相关文章

升级redis3.2.7编译报错“ undefined reference to `clock_gettime&#39;”

由于redis有个紧急的安全漏洞更新所以我升级线上的redis-cluster的版本.编译时报了一个错:" redis-3.2.7/deps/jemalloc/src/nstime.c:120: undefined reference to `clock_gettime' collect2: ld returned 1 exit status make[1]: *** [redis-server] Error 1 make[1]: Leaving directory `redis-3.2.7/s

linux + eclipse + cdt 报错undefined reference......好麻烦的,这位大牛给出的方法可行,特此MARK!!!!

http://bbs.csdn.net/topics/390239632 kerosun kerosun 等级: 结帖率:96.92% 楼主 发表于: 2012-10-11 12:00:51 比如有一个tools工程,提供给其他工程通用的工具函数. 我现在的做法就只能是ctrl+c|ctrl+v一旦工具函数发生变化,还需要在用到这些函数的工程中更新,比较麻烦. 看到eclipse工程属性设置中有Project References,但是一直不会用.那位好心人能说说怎样实现我的需求. 更多0分享到

安装mysql_sniffer报错undefined reference to symbol &#39;[email&#160;protected]@GLIBC_2.2.5&#39;问题

按照https://github.com/Qihoo360/mysql-sniffer上的安装方法进行安装,make是报错如下 Linking CXX executable mysql-sniffer /usr/bin/ld: /root/mysql-sniffer/lib/libgthread-2.0.a(gthread-impl.o): undefined reference to symbol '[email protected]@GLIBC_2.2.5' //usr/lib64/libp

cocos2d-x android 添加新场景报错: undefined reference to `vtable for XXX&#39;

转载自 居家懒人 http://www.cnblogs.com/JD85/archive/2012/09/17/2688128.html 加入写了新场景SecondScene,结果在cpp文件里类名地方报错说undefined reference to `vtable for SecondScene', 很简单,貌似是每个新场景都要先注册一下,找到jni-->Classes目录下的Android.mk文件,在 LOCAL_SRC_FILES := AppDelegate.cpp HelloWor

php make报错undefined reference to symbol

/usr/bin/ld: ext/phar/.libs/util.o: undefined reference to symbol '[email protected]@libcrypto.so.10' /usr/bin/ld: note: '[email protected]@libcrypto.so.10' is defined in DSO /lib64/libcrypto.so.10 so try adding it to the linker command line /lib64/l

Centos6.3 PHP编译安装JSON模块报错解决

我在搭建监控系统时候出现JSON模块安装失败,PHP5.3  系统Centos6.3,安装json报错 ZVAL_DELREF 符号未知错误... # Warning: PHP Startup: Unable to load dynamic library '/home/json/json-1.2.1/modules/json.so' - /home/json/json-1.2.1/modules/json.so: undefined symbol: ZVAL_DELREF in Unknown

单独编译apache的rewrite模块

 单独编译apache的rewrite模块 当我们编译安装好apache的时候,就像这样: ./configure \ --prefix=/usr/local/apache \   //安装的路径 --with-included-apr \        // 跨平台 --enable-so \                 //启用DSO --enable-deflate=shared \    //动态共享的方式编译deflate模块 --enable-expires=shared \  

一招解决OpenERP8.0安装旧版模块报错

有喜欢尝鲜的网友开始玩8.0了,可是版本还没发布,社区的很多特别好的模块还没有升级到8,所以经常碰到模块无法安装的问题. No module name osv 网友提出将模块的 from osv import osv,fields 改为 from openerp.osv import osv,fields 其实这是一个编程规范问题,旧版模块代码里很多这种导入方式,一个一个改对于不懂代码的或者openerp新手是不现实的. 众所周知,openerp的运行入口是openerp-server.py,在

ansible执行shell模块和command模块报错| FAILED | rc=127 &gt;&gt; /bin/sh: lsof: command not found和| rc=2 &gt;&gt; [Errno 2] No such file or directory

命令: ansible -i hosts_20 st  -m shell -a 'service zabbix_agentd star'  -K --become ansible -i hosts_20 st  -m shell -a 'lsof -i:10050'  -K --become 在shell模块报错:| FAILED | rc=127 >>/bin/sh: lsof: command not found 在command模块报错:| rc=2 >>[Errno 2]