解决Ubuntu16.04下使用PCL库报错的问题


发布于

|

分类

PCL 库全称是“Point Cloud Library”,介绍是“The Point Cloud Library (PCL) is a standalone, large scale, open project for 2D/3D image and point cloud processing. ”(我只是懒得翻译了…… 囧)。但是这个库好像在 Ubuntu 16.04 里面会出现一点问题。

首先,这个库的 用法 是这样的:

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(MY_GRAND_PROJECT)
find_package(PCL 1.3 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcd_write_test pcd_write.cpp)
target_link_libraries(pcd_write_test ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})

在 Ubuntu16.04 下,直接这样用的话会报错:

/usr/bin/ld: 找不到 -lvtkproj4
/usr/bin/ld: 找不到 -lvtkproj4
collect2: error: ld returned 1 exit status
CMakeFiles/MY_GRAND_PROJECT.dir/build.make:380: recipe for target 'MY_GRAND_PROJECT' failed
make[3]: *** [MY_GRAND_PROJECT] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/MY_GRAND_PROJECT.dir/all' failed
make[2]: *** [CMakeFiles/MY_GRAND_PROJECT.dir/all] Error 2
CMakeFiles/Makefile2:116: recipe for target 'CMakeFiles/MY_GRAND_PROJECT.dir/rule' failed
make[1]: *** [CMakeFiles/MY_GRAND_PROJECT.dir/rule] Error 2
Makefile:131: recipe for target 'MY_GRAND_PROJECT' failed
make: *** [MY_GRAND_PROJECT] Error 2

没错,就是那个 “vtkproj4” 惹的祸。但是搜遍了 synaptic,并没有 vtkproj4 这个东西。第一反应是去 /var/lib 里面做 ln 去,但是不知道该给谁做 ln。Google 了一天,在 这个帖子 上发现了一点端倪。参照自己的情况改了一下,就成功了。

帖子里面说,将 list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4") 或者 list(REMOVE_ITEM VTK_LIBRARIES "vtkproj4") 加入 CMakelists.txt。直接使用这句话,依然报错,随发现我的项目中没有 PCL_LIBRARIES 这个变量。那么,应该把这个变量替换成什么呢?

发现在 target_link_libraries(MY_GRAND_PROJECT ${OpenCV_LIBS} ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES}) 里面,有 PCL 的两个变量。逐个尝试,最终发现替换成 PCL_IO_LIBRARIES 这个变量就好了。所以,最终,把下面这句话加入 CMakelist:

list(REMOVE_ITEM PCL_IO_LIBRARIES "vtkproj4")

世界清净了。


最近也不知道在忙什么,老板也开始催进度了。

神烦。

参考资料


评论

  1. tsai 的头像
    tsai

    I added

    list(REMOVE_ITEM PCL_IO_LIBRARIES "vtkproj4")
    

    into CMakeLists.txt and it is OK now.

    thanks for the post.

    1. darren guo 的头像
      darren guo

      Hi, could you tell me how you find it is PCL_IO_LIBRARIES? could you tell me the detailed steps and command? I am not familiar with Ubuntu, and it still fails when i added list(REMOVE_ITEM PCL_IO_LIBRARIES "vtkproj4") in my CMakefilelist file, thank you very much.

    2. 小金鱼儿 的头像
      小金鱼儿

      Hi~

      Do you use CLion IDE? You can find all compile settings in some windows/tabs. Just try to modify it~

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注