一、问题描述
在使用PCL做点云拼接工程中,make后出现缺少库的错误:No rule to make target '/usr/lib/x86_64-linux-gnu/libproj.so',
错误具体如下:
make[2]: *** No rule to make target '/usr/lib/x86_64-linux-gnu/libproj.so', needed by 'joinMap'. Stop.
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/joinMap.dir/all' failed
make[1]: *** [CMakeFiles/joinMap.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
二、问题原因:
出现缺少库的情况,通常有两种原因:
- 此库并未被安装。
- 此库已安装,但并未链接到此工程。(如工程中需要库的名字是:libproj4.so。但我们实际拥有:libvtkproj4.so.5.10.1,这时需要做一个链接。)
三、解决办法:
在 /usr/lib下寻找是否有 libproj.so库,如果没有则下载;如果显示已安装,则需要将这个库链接到工程。
为了得到详细的错误原因,我们运行下面代码:
make --debug
得到如下运行结果:
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating goal targets....File 'default_target' does not exist.File 'all' does not exist.File 'cmake_check_build_system' does not exist.Must remake target 'cmake_check_build_system'.Successfully remade target file 'cmake_check_build_system'.Must remake target 'all'.
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating goal targets....File 'all' does not exist.File 'CMakeFiles/joinMap.dir/all' does not exist.Must remake target 'CMakeFiles/joinMap.dir/all'.
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating goal targets....File 'CMakeFiles/joinMap.dir/depend' does not exist.
Must remake target 'CMakeFiles/joinMap.dir/depend'.
Scanning dependencies of target joinMap
Successfully remade target file 'CMakeFiles/joinMap.dir/depend'.
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating goal targets....File 'CMakeFiles/joinMap.dir/build' does not exist.File 'joinMap' does not exist.File 'CMakeFiles/joinMap.dir/joinMap.cpp.o' does not exist.Must remake target 'CMakeFiles/joinMap.dir/joinMap.cpp.o'.
[ 50%] Building CXX object CMakeFiles/joinMap.dir/joinMap.cpp.oSuccessfully remade target file 'CMakeFiles/joinMap.dir/joinMap.cpp.o'.File '/usr/lib/x86_64-linux-gnu/libproj.so' does not exist.Must remake target '/usr/lib/x86_64-linux-gnu/libproj.so'.
make[2]: *** No rule to make target '/usr/lib/x86_64-linux-gnu/libproj.so', needed by 'joinMap'. Stop.
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/joinMap.dir/all' failed
make[1]: *** [CMakeFiles/joinMap.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
重点在于其中的这两句:
File '/usr/lib/x86_64-linux-gnu/libproj.so' does not exist.Must remake target '/usr/lib/x86_64-linux-gnu/libproj.so'.
现在我们已确定 libproj.so库不存在,接下来去下载它。查找我们所需库的标准形式,执行指令如下:
apt-cache search libproj*
得到:
libproc-waitstat-perl - interpret and act on wait() status values
libprocess-cpp-dev - C++11 library for handling processes - dev headers and libraries
libprocess-cpp-doc - Documentation files for libprocess-cpp-dev
libprocess-cpp3 - C++11 library for handling processes - runtime library
libprocps4 - library for accessing process information from /proc
libprocps4-dev - library for accessing process information from /proc
libproperties-cpp-dev - C++11 library providing properties/signals. - dev headers
libproperties-cpp-doc - Documentation files for libproperties-cpp-dev
libprotobuf-dev - protocol buffers C++ library (development files)
libprotobuf-lite9v5 - protocol buffers C++ library (lite version)
libprotobuf9v5 - protocol buffers C++ library
libprotoc-dev - protocol buffers compiler library (development files)
libprotoc9v5 - protocol buffers compiler library
libproxy-cil-dev - automatic proxy configuration management library (CLI devel)
libproxy-dev - automatic proxy configuration management library (devel)
libproxy0.4-cil - automatic proxy configuration management library (CLI)
libproxy1-plugin-gsettings - automatic proxy configuration management library (GSettings plugin)
libproxy1-plugin-networkmanager - automatic proxy configuration management library (Network Manager plugin)
libproxy1v5 - automatic proxy configuration management library (shared)
libprobe-perl-perl - module to obtain information about the currently running Perl interpreter
libproc-background-perl - generic interface for Unix and Win32 background process management
libproc-daemon-perl - module for running scripts as daemons
libproc-fork-perl - Perl interface to the fork() system call
libproc-invokeeditor-perl - Perl extension for starting a text editor
libproc-pid-file-perl - Perl module for managing process id files
libproc-processtable-perl - Perl library for accessing process table information
libproc-queue-perl - Perl module to limit the number of child processes
libproc-reliable-perl - Perl module to run external processes reliably
libproc-simple-perl - Perl interface to launch and control background processes
libproc-syncexec-perl - spawn processes but report exec() errors properly
libproc-terminator-perl - module to conveniently terminate processes
libproc-wait3-perl - Perl interface to the wait3() system call
libprocesscore7 - library for monitoring your system - shared library
libprocessing-core-java - Java animation and interaction library
libprocessui7 - library for monitoring your system - shared library
libproj-dev - Cartographic projection library (development files)
libproj-java - Cartographic projection library (JNI bindings)
libproj9 - Cartographic projection library
libprojectm-dev - Advanced Milkdrop-compatible music visualization library - dev
libprojectm-qt-dev - projectM Qt4 (development files)
libprojectm-qt1v5 - projectM Qt4 bindings
libprojectm2v5 - Advanced Milkdrop-compatible music visualization library
libpromises3 - libpromises library for cfengine3 binaries
libproperties-maven-plugin-java - Maven Plugin to read and write property files from mojo.codehaus.org
libproperties-maven-plugin-java-doc - Documentation for Properties Maven Plugin
libprophet-perl - distributed, peer-to-peer replicated database system
libprotobuf-c-dev - Protocol Buffers C static library and headers (protobuf-c)
libprotobuf-c1 - Protocol Buffers C shared library (protobuf-c)
libprotobuf-c1-dbg - Protocol Buffers C shared library debug symbols (protobuf-c)
libprotobuf-java - Java bindings for protocol buffers
libprotocol-osc-perl - module to implement (de)coding and processing of OSC packets
libprotozero-dev - Minimalistic protocol buffer decoder and encoder in C++
libprotozero-doc - Minimalistic protocol buffer decoder and encoder in C++ - docs
libproxool-java - Java JDBC connection pool
libproxy-tools - automatic proxy configuration management library (tools)
libproxy1-plugin-kconfig - automatic proxy configuration management library (KConfig plugin)
libproxy1-plugin-webkit - automatic proxy configuration management library (Webkit plugin)
libproxychains-dev - proxy chains -- shared library (development)
libproxychains3 - proxy chains -- shared library (runtime)
projectm-data - Advanced Milkdrop-compatible music visualization library - data
protobuf-c-compiler - Protocol Buffers C compiler (protobuf-c)
python-libproxy - automatic proxy configuration management library (python)
得知所需库包含在 libproj-dev中,运行如下指令,进行安装:
sudo apt-get install libproj-dev
我们发现,文件make成功了,但还是无法显示点云文件,因为报了第二个错误,如下:
Scanning dependencies of target joinMap
[ 50%] Building CXX object CMakeFiles/joinMap.dir/joinMap.cpp.o
[100%] Linking CXX executable joinMap
/usr/bin/ld: cannot find -lvtkproj4
collect2: error: ld returned 1 exit status
CMakeFiles/joinMap.dir/build.make:377: recipe for target 'joinMap' failed
make[2]: *** [joinMap] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/joinMap.dir/all' failed
make[1]: *** [CMakeFiles/joinMap.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
现在开始着手解决第二个错误。通过 make --debug得知,又是库的问题。所以我们首先在 /usr/lib里面使用通配符*搜索 libvtkproj*
anan@ubuntu:~$ cd /usr/lib
anan@ubuntu:/usr/lib$ ls libvtkproj*
得到如下结果:
libvtkproj4.so.5.10 libvtkproj4.so.5.10.1
libvtkproj4.so.5.10(蓝色) libvtkproj4.so.5.10.1(白色)。其中:蓝色表示链接库文件,白色表示源文件。
从而得知系统中存在 libvtkproj4.so 文件,只是我们所运行的程序不认识此版本号(libvtkproj4.so.5.10.1)。所以只需要做一个库链接,就可以解决问题。
*系统中已存在一个链接库,可以看一下它效果:
libvtkproj4.so.5.10 是 libvtkproj4.so.5.10.1 的链接文件。
链接库的制作方法也很简单,只需要输入如下命令:
sudo ln -s libvtkproj4.so.5.10.1 libvtkproj4.so
即可得到:
此时再回到 build中重新cmake、make一下,程序就运行成功了。
补充技巧:
usr/bin 多放置可执行文件;usr/lib 多放置库文件。
当缺少库时,我们首先去lib中检查。库文件(lib)的两种格式:.so; .a