[原创] 解决编译ELL的错误:undefined reference to `cblas_xxx'

OS:Ubuntu 14.04 LTS
在PC上编译ELL的时候,尽管你可能已经安装了所有ELL文档中要求的软件依赖,可能还是会遇到 undefined reference to `cblas_xxx' 的错误,如下:

0%] Built target documentation
[ 10%] Built target utilities
[ 11%] Built target math
[ 14%] Built target data
[ 23%] Built target emitters
[ 24%] Built target evaluators
[ 28%] Built target functions
[ 37%] Built target model
[ 39%] Built target predictors
[ 48%] Built target nodes
[ 52%] Built target trainers
[ 59%] Built target common
[ 60%] Built target testing
[ 61%] Linking CXX executable common_test
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Copy(int, float const*, int, float*, int)': BlasWrapper.cpp:(.text+0x31): undefined reference tocblas_scopy'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Copy(int, double const*, int, double*, int)': BlasWrapper.cpp:(.text+0x69): undefined reference tocblas_dcopy'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Asum(int, float const*, int)': BlasWrapper.cpp:(.text+0x92): undefined reference tocblas_sasum'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Asum(int, double const*, int)': BlasWrapper.cpp:(.text+0xba): undefined reference tocblas_dasum'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Nrm2(int, float const*, int)': BlasWrapper.cpp:(.text+0xf0): undefined reference tocblas_snrm2'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Nrm2(int, double const*, int)': BlasWrapper.cpp:(.text+0x118): undefined reference tocblas_dnrm2'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Scal(int, float, float*, int)': BlasWrapper.cpp:(.text+0x15b): undefined reference tocblas_sscal'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Scal(int, double, double*, int)': BlasWrapper.cpp:(.text+0x193): undefined reference tocblas_dscal'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Axpy(int, float, float const*, int, float*, int)': BlasWrapper.cpp:(.text+0x1d9): undefined reference tocblas_saxpy'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Axpy(int, double, double const*, int, double*, int)': BlasWrapper.cpp:(.text+0x221): undefined reference tocblas_daxpy'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Dot(int, float const*, int, float const*, int)': BlasWrapper.cpp:(.text+0x259): undefined reference tocblas_sdot'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Dot(int, double const*, int, double const*, int)': BlasWrapper.cpp:(.text+0x290): undefined reference tocblas_ddot'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Gemv(CBLAS_ORDER, CBLAS_TRANSPOSE, int, int, float, float const*, int, float const*, int, float, float*, int)': BlasWrapper.cpp:(.text+0x309): undefined reference tocblas_sgemv'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Gemv(CBLAS_ORDER, CBLAS_TRANSPOSE, int, int, double, double const*, int, double const*, int, double, double*, int)': BlasWrapper.cpp:(.text+0x37c): undefined reference tocblas_dgemv'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Gemm(CBLAS_ORDER, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, int, int, int, float, float const*, int, float const*, int, float, float*, int)': BlasWrapper.cpp:(.text+0x3f5): undefined reference tocblas_sgemm'
../math/libmath.a(BlasWrapper.cpp.o): In function ell::math::Blas::Gemm(CBLAS_ORDER, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, int, int, int, double, double const*, int, double const*, int, double, double*, int)': BlasWrapper.cpp:(.text+0x471): undefined reference tocblas_dgemm'
collect2: error: ld returned 1 exit status
make[2]: *** [libraries/common/common_test] Error 1
make[1]: *** [libraries/common/CMakeFiles/common_test.dir/all] Error 2
make: *** [all] Error 2

这个问题是由于我的Ubuntu 14.04同时安装了blasatlas导致的——我真的不记得我是什么时候安装的atlas了。在这种情况下,从make的前一步,也就是cmake的输出信息中,可以看出一些端倪(所以说在cmake的时候一定要仔细检查):

-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Blas libraries: /usr/lib/libf77blas.so;/usr/lib/libatlas.so
-- Blas linker flags:
-- Blas include directories:
-- Using BLAS include path: /usr/include
-- Using BLAS library: /usr/lib/libf77blas.so;/usr/lib/libatlas.so
-- Using BLAS DLLs:
-- Found PythonInterp: /home/codelast/.miniconda3/bin/python (found version "3.6.1")
-- Found PythonLibs: /home/codelast/.miniconda3/lib/libpython3.6m.so (found version "3.6.1")
-- Found SWIG: /usr/local/bin/swig (found suitable version "3.0.12", minimum required is "3.0.12")
-- Creating wrappers for python
-- Creating wrappers for javascript
-- Creating wrappers for xml
-- Using python found at: /home/codelast/.miniconda3/bin/python
-- Using python libraries found at: /home/codelast/.miniconda3/lib/libpython3.6m.so
-- Creating wrappers for python
-- Generated target compiled_vgg16ImageNet_host
-- Generated target compiled_vgg16ImageNet_pi3
-- Generated target compiled_vgg16ImageNet_pi0
-- Generated target compiled_darknetReference_host
-- Generated target compiled_darknetReference_pi3
-- Generated target compiled_darknetReference_pi0
-- Configuring done
-- Generating done
-- Build files have been written to: /home/codelast/programme/pi/ELL/build
上面标红的那两句,表明atlas library会被当作blas library来用,这就会导致后面的编译错误。
所以,我查找了一下Ubuntu系统中已经安装的atlas package:

sudo dpkg -l | grep atlas
输出如下:
ii  libatlas-base-dev                                           3.10.1-4                                            amd64        Automatically Tuned Linear Algebra Software, generic static
ii  libatlas-dev                                                3.10.1-4                                            all          Automatically Tuned Linear Algebra Software, C header files
ii  libatlas3-base                                              3.10.1-4                                            amd64        Automatically Tuned Linear Algebra Software, generic shared

然后把这3个package都卸载掉:

sudo apt-get remove libatlas-base-dev libatlas-dev ibatlas3-base

文章来源:https://www.codelast.com/
然后再重新cmake,输出信息如下:

-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Blas libraries: /usr/lib/libblas.so
-- Blas linker flags: 
-- Blas include directories: 
-- Using BLAS include path: /usr/include
-- Using BLAS library: /usr/lib/libblas.so
-- Using BLAS DLLs: 
-- Found PythonInterp: /home/codelast/.miniconda3/bin/python (found version "3.6.1") 
-- Found PythonLibs: /home/codelast/.miniconda3/lib/libpython3.6m.so (found version "3.6.1") 
-- Found SWIG: /usr/local/bin/swig (found suitable version "3.0.12", minimum required is "3.0.12") 
-- Creating wrappers for python
-- Creating wrappers for javascript
-- Creating wrappers for xml
-- Using python found at: /home/codelast/.miniconda3/bin/python
-- Using python libraries found at: /home/codelast/.miniconda3/lib/libpython3.6m.so
-- Creating wrappers for python
-- Generated target compiled_vgg16ImageNet_host
-- Generated target compiled_vgg16ImageNet_pi3
-- Generated target compiled_vgg16ImageNet_pi0
-- Generated target compiled_darknetReference_host
-- Generated target compiled_darknetReference_pi3
-- Generated target compiled_darknetReference_pi0
-- Configuring done
-- Generating done
-- Build files have been written to: /home/codelast/programme/pi/ELL/build
从标蓝的那两句,可见我已经成功地把atlas给除掉了。
此时,再重新make,就能成功编译ELL了!
文章来源:https://www.codelast.com/
➤➤ 版权声明 ➤➤ 
转载需注明出处:codelast.com 
感谢关注我的微信公众号(微信扫一扫):

wechat qrcode of codelast

发表评论