liblapacke:对符号'dposv_'的未定义引用

时间:2018-11-22 13:58:28

标签: makefile cmake linker

我正在尝试编译该库:https://github.com/dthuerck/culip,但是在制作过程中出现以下错误:

[ 73%] Linking CXX executable culip-tests-la
/usr/bin/cmake -E cmake_link_script CMakeFiles/culip-tests-la.dir/link.txt --verbose=1
/usr/bin/c++    -fPIC -fopenmp -march=native -m64 -DGPU_BLAS -Wfatal-errors -O3   CMakeFiles/culip-tests-la.dir/tests/la/test_sparse.cc.o CMakeFiles/culip-tests-la.dir/tests/la/test_spmv.cc.o CMakeFiles/culip-tests-la.dir/tests/la/test_sqmr.cc.o  -o culip-tests-la  -L/gcc/home/sahmad/Desktop/culip/dependencies/mmio/lib -rdynamic /usr/local/cuda-9.1/lib64/libcudart_static.a -lpthread -ldl -lrt liblibutils.so liblibdatastructures.so liblibla.so liblibalgorithms.so -lmmio liblibtest.so -lblas -lhwloc -lgfortran -lblas -llapacke -lmmio ../dependencies/gtest/lib/libgtest.so ../dependencies/gtest/lib/libgtest_main.so /usr/local/cuda-9.1/lib64/libcudart_static.a -lpthread -ldl -lrt /usr/local/cuda-9.1/lib64/libcublas.so /usr/local/cuda-9.1/lib64/libcusparse.so /usr/local/cuda-9.1/lib64/libcusolver.so /usr/local/cuda-9.1/lib64/libcudadevrt.a -lblas -lhwloc -lgfortran -llapacke ../dependencies/gtest/lib/libgtest.so ../dependencies/gtest/lib/libgtest_main.so /usr/local/cuda-9.1/lib64/libcublas.so /usr/local/cuda-9.1/lib64/libcusparse.so /usr/local/cuda-9.1/lib64/libcusolver.so /usr/local/cuda-9.1/lib64/libcudadevrt.a /usr/local/cuda-9.1/lib64/libcudart_static.a -lpthread -ldl -lrt -Wl,-rpath,/gcc/home/sahmad/Desktop/culip/build:/gcc/home/sahmad/Desktop/culip/dependencies/mmio/lib:/gcc/home/sahmad/Desktop/culip/dependencies/gtest/lib:/usr/local/cuda-9.1/lib64 
/usr/bin/ld: /gcc/home/sahmad/Downloads/lapack-3.8.0/liblapacke.a(lapacke_dposv_work.o): undefined reference to symbol 'dposv_'
//usr/lib/libopenblas.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/culip-tests-la.dir/build.make:171: recipe for target 'culip-tests-la' failed
make[2]: *** [culip-tests-la] Error 1
make[2]: Leaving directory '/gcc/home/sahmad/Desktop/culip/build'
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/culip-tests-la.dir/all' failed
make[1]: *** [CMakeFiles/culip-tests-la.dir/all] Error 2
make[1]: Leaving directory '/gcc/home/sahmad/Desktop/culip/build'
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

我知道这是一个常见错误,我已经尝试按照其他解决方案来解决类似错误,但是由于我对Ubuntu和C ++的经验很少,因此无法解决。显然这是一种链接错误,我尝试以不同的顺序链接库,但是还没有运气。

我正在使用gcc 5.4.0和CUDA 9.1在Ubuntu 16.04上工作。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

Lapacke是lapack的接口:lapack未嵌入在lapacke中。因此,都需要链接。。此外,顺序也很重要:左侧库中使用的所有功能必须由右侧库定义。 结果,您可以尝试链接-llapacke -llapack -lblas -lm吗?

更具体地说,在测试中的某个时刻,函数dposv_被调用,并且此函数在Lapack中实现,而不是在Lapacke中实现。实际上,Lapacke包含一个接口LAPACKE_dposv(),调用LAPACKE_dposv_work(),调用LAPACK_dposv(),即LAPACK_GLOBAL(dposv,DPOSV),在您的平台上沸腾到dposv_

在Cmake中,如果lapack库位于您的库搜索路径中,则可以在本地CMakeLists.txt中修改target_link_libraries()

target_link_libraries(culip-tests-la lapacke lapack blas m)

最好的方法是将以下命令添加到CMakeLists.txt中,以确保已安装并找到了Blas和Lapack:

find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)

最后一行设置 FindLAPACK.html FindLAPACK.cmake中定义的LAPACK_LIBRARIESLAPACK_LINKER_FLAGS之类的标志。然后(与CMake link atlas and llapack中一样):

target_compile_options(culip-tests-la ${LAPACK_LINKER_FLAGS})
target_link_libraries(culip-tests-la lapacke ${LAPACK_LIBRARIES})

find_package(BLAS REQUIRED)行是多余的,因为这几乎是 FindLAPACK.cmake中要做的第一件事。此外,变量${LAPACK_LIBRARIES}可能包含类似-llapack -lblas -lm之类的内容。可以通过以下方式打印:

message( ${LAPACK_LIBRARIES} )