我的系统上已安装gfortran,该文件libgfortran.a
位于/usr/lib/gcc/x86_64-linux-gnu/4.6/
。使用nm
我确保_gfortran_compare_string
在其中定义了函数:
$ nm /usr/lib/gcc/x86_64-linux-gnu/4.6/libgfortran.a | grep _gfortran_compare_string
退货
0000000000000000 T _gfortran_compare_string
0000000000000000 T _gfortran_compare_string_char4
但是,我的CUDA-C程序的链接器抛出错误:
/usr/local/cuda-6.0/bin/nvcc --cudart static -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/home/chung/lapack-3.5.0 -link -o "pQP" ./src/pQP.o -lgfortran -llapacke -llapack -lcublas -lblas -lcurand
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
/home/chung/lapack-3.5.0/liblapack.a(ilaenv.o): In function `ilaenv_':
ilaenv.f:(.text+0x81): undefined reference to `_gfortran_compare_string'
后来又出现了另一个错误,再次与libgfortran有关:
/home/chung/lapack-3.5.0/liblapack.a(xerbla.o): In function `xerbla_':
xerbla.f:(.text+0x49): undefined reference to `_gfortran_st_write'
xerbla.f:(.text+0x54): undefined reference to `_gfortran_string_len_trim'
xerbla.f:(.text+0x66): undefined reference to `_gfortran_transfer_character_write'
xerbla.f:(.text+0x76): undefined reference to `_gfortran_transfer_integer_write'
xerbla.f:(.text+0x7e): undefined reference to `_gfortran_st_write_done'
xerbla.f:(.text+0x87): undefined reference to `_gfortran_stop_string'
但是,再次使用nm,我发现_gfortran_st_write
libgfortran.a中定义了等等。
注意: Lapack使用libgfortran。我最近安装了lapack并运行了所有测试,所有测试都通过了。
您需要更改为链接器指定静态库的顺序。如果您执行以下操作:
nvcc --cudart static -L/usr/lib/gcc/x86_64-linux-gnu/4.6 \
-L/home/chung/lapack-3.5.0 -link -o "pQP" ./src/pQP.o \
-llapacke -llapack -lcublas -lblas -lcurand -lgfortran
您应该会发现它会起作用。
根本原因(这是gcc / gnu工具链的特征,与nvcc无关)是gnu链接器从左到右解析了静态库的链接依赖项列表。如果在任何依赖它的库之前指定一个静态库,则将被跳过,因为在初次遇到该静态库时,它在链接列表中没有依赖性。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句