编译CPP工程时,提示找不到 boost_python 和 boost_numpy。
$ make
[ 50%] Linking CXX shared library segment.so
/usr/bin/ld: cannot -lboost_python
/usr/bin/ld: cannot found -lboost_numpy
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/segment.dir/build.make:84:segment.so] 错误 1
make[1]: *** [CMakeFiles/Makefile2:76:CMakeFiles/segment.dir/all] 错误 2
make: *** [Makefile:84:all] 错误 2
set(BOOST_LIBS "-lboost_system -lboost_python -lboost_numpy")
sudo apt-cache search libboost-python
sudo apt-cache search libboost-numpy
sudo apt-get install libboost-numpy-dev libboost-python-dev
# RESULT
libboost-numpy-dev 已经是最新版 (1.71.0.0ubuntu2)。
libboost-python-dev 已经是最新版 (1.71.0.0ubuntu2)。
具体版本是:libboost-python1.71.0_1.71.0-6ubuntu6_arm64.deb,发现该软件包包含如下软件:
/usr/lib/aarch64-linux-gnu/libboost_python38.so.1.71.0
/usr/share/doc/libboost-python1.71.0/changelog.Debian.gz
/usr/share/doc/libboost-python1.71.0/copyright
/usr/share/lintian/overrides/libboost-python1.71.0
set(BOOST_LIBS "-lboost_system -lboost_python38 -lboost_numpy38")
$ make
[ 50%] Building CXX object CMakeFiles/segment.dir/segment_py.cpp.o
[100%] Linking CXX shared library segment.so
[100%] Built target segment
sudo apt-get install libboost-numpy-dev libboost-python-dev
set(BOOST_LIBS "-lboost_system -lboost_python38 -lboost_numpy38")
$ ldconfig -p | grep boost_python
libboost_python38.so.1.71.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libboost_python38.so.1.71.0
libboost_python38.so.1.67.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libboost_python38.so.1.67.0
libboost_python38.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libboost_python38.so
libboost_python27.so.1.67.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libboost_python27.so.1.67.0
$ ldconfig -p | grep boost_numpy
libboost_numpy38.so.1.71.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libboost_numpy38.so.1.71.0
libboost_numpy38.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libboost_numpy38.so
$ sudo find / -name "pyconfig.h"
/home/larry/anaconda3/pkgs/python-3.8.11-h12debd9_0_cpython/include/python3.8/pyconfig.h
/home/larry/anaconda3/include/python3.7m/pyconfig.h
/usr/include/python3.8/pyconfig.h
/usr/include/x86_64-linux-gnu/python3.8/pyconfig.h
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/include/python3.8
$ make
Scanning dependencies of target segment
[ 50%] Building CXX object CMakeFiles/segment.dir/segment_py.cpp.o
/home/larry/GitProjects/selective_search_py/segment_py.cpp:4:10: fatal error: boost/numpy.hpp: 没有那个文件或目录
4 | #include
| ^~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/segment.dir/build.make:63:CMakeFiles/segment.dir/segment_py.cpp.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:76:CMakeFiles/segment.dir/all] 错误 2
make: *** [Makefile:84:all] 错误 2
#include
#include
numpy.hpp
与 python.hpp
,发现这两个文件都在 /usr/include/boost/ 目录下,所以编译时,如果找不到头文件可以在 g++ 编译器后添加参数 -I/usr/include/boost/python/ 。numpy.hpp
在 /usr/include/boost/python 下,所以使用 numpy.hpp
的头文件包含应该是 include
$ sudo find / -name "numpy.hpp"
/usr/include/vtk-7.1/vtkdiy/io/numpy.hpp
/usr/include/boost/python/numpy.hpp
$ sudo find / -name "python.hpp"
/usr/include/boost/mpi/python.hpp
/usr/include/boost/python.hpp
/usr/include/boost/parameter/python.hpp
#include
#include