今天看到网上的一个 wukong-robot 开源项目,可以在家里实现的智能音箱项目,所以打算在测试机上部署一下玩玩呐,结果在变异snowboy库时,遇到了个小问题,在编译时报错信息如下:
g++ -I../../ -O3 -fPIC -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++0x -shared snowboy-detect-swig.o \
../..//lib/ubuntu64/libsnowboy-detect.a -L/pydev/anaconda3/lib/python3.6/config-3.6m-x86_64-linux-gnu -L/pydev/anaconda3/lib -lpython3.6m -lpthread -ldl -lutil -lrt -lm -Xlinker -export-dynamic -lm -ldl -lf77blas -lcblas -llapack -latlas -o _snowboydetect.so
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: 找不到 -lf77blas
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: 找不到 -lcblas
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: 找不到 -latlas
collect2: error: ld returned 1 exit status
make: *** [Makefile:73:_snowboydetect.so] 错误 1
什么原因呢?
这个问题可以理解为找不到这三个库文件,通常有两种情况:
- 没安装这几个库文件
- 安装了,却无法找到
按照网上对依赖包的提示, 我安装下面这些包试一试:
sudo zypper in cblas-devel blas-devel libcblas3 atlascpp-devel gap-atlasrep libatlas3-basic libatlas3-basic-devel
之后,再次执行 make 命令还是有错误如下:
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: 找不到 -lf77blas
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: 找不到 -latlas
接着发现 atlas 库文件目录 /usr/lib64/atlas
下是空的, 而 /usr/lib64/atlas-basic
下面有 atlas 动态库文件.
那问题可能出现在 Makefile
文件中了, 所以找到 引用动态库的变量位置,添加一下库查找目录再试试,下面是Makefile修改部分内容:
# Make sure you have Atlas installed. You can statically link Atlas if you
# would like to be able to move the library to a machine without Atlas.
ifneq ("$(ldconfig -p | grep lapack_atlas)","")
LDLIBS := -L/usr/lib64/atlas-basic/ -lm -ldl -lf77blas -lcblas -llapack_atlas -latlas
else
LDLIBS := -L/usr/lib64/atlas-basic/ -lm -ldl -lf77blas -lcblas -llapack -latlas
endif
看到了吧,添加了-L/usr/lib64/atlas-basic/
内容, 再次执行 make
命令:
make
swig -I../../ -c++ -python -o snowboy-detect-swig.cc snowboy-detect-swig.i
g++ -I/pydev/anaconda3/envs/py3.8/include/python3.8 -I/pydev/anaconda3/envs/py3.8/include/python3.8 -Wno-unused-result -Wsign-compare -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O3 -ffunction-sections -pipe -fdebug-prefix-map=/tmp/build/80754af9/python_1573076469108/work=/usr/local/src/conda/python-3.8.0 -fdebug-prefix-map=/pydev/anaconda3/envs/py3.8=/usr/local/src/conda-prefix -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -flto -DNDEBUG -fwrapv -O3 -Wall -I../../ -O3 -fPIC -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++0x -c snowboy-detect-swig.cc
g++ -I../../ -O3 -fPIC -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++0x -shared snowboy-detect-swig.o \
../..//lib/ubuntu64/libsnowboy-detect.a -L/pydev/anaconda3/envs/py3.8/lib/python3.8/config-3.8-x86_64-linux-gnu -L/pydev/anaconda3/envs/py3.8/lib -lcrypt -lpthread -ldl -lutil -lrt -lm -lm -L/usr/lib64/atlas-basic/ -lm -ldl -lf77blas -lcblas -llapack -latlas -o _snowboydetect.so
问题解决了!
回顾一下,这个问题解决过程:
- 安装缺失的库文件
- 修改 Makefile 文件中缺失查找库文件路径.
上面的问题其实在编写代码引用库文件过程中常常遇到的, 如果你遇到类似的问题,可以按照这两个步骤来解决它.
网友评论