无法链接到libgfortran.a [英] Unable to link to libgfortran.a
问题描述
我有gfortran安装在我的系统和文件 libgfortran.a
可以在 / usr / lib / gcc / x86_64-linux- gnu / 4.6 /
。使用 nm
我确保函数 _gfortran_compare_string
在其中定义:
I have gfortran installed on my system and the file libgfortran.a
can be found at /usr/lib/gcc/x86_64-linux-gnu/4.6/
. Using nm
I made sure that the function _gfortran_compare_string
is defined in there:
$ 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程序引发错误:
But, the linker of my CUDA-C program throws errors:
/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有关:
and later on another error, again related to 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中定义。
But, again using nm, I found that _gfortran_st_write
, etc are defined in libgfortran.a.
注意: Lapack使用libgfortran。我最近安装了lapack并运行所有的测试,他们都通过了。
Note: Lapack makes use of libgfortran. I recently installed lapack and ran all the tests and they all passed.
推荐答案
您需要更改您指定的顺序static库到链接器。如果你这样做:
You need to change the order in which you specify static libraries to the linker. If you do something like this:
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
您应该会发现它会工作。
You should find it will work.
底层原因(这是gcc / gnu工具链的一个特点,而不是nvcc的任务)是静态库的链接依赖列表从左边解析到右边的gnu链接器。如果您在任何依赖于它的库之前指定了一个静态库,那么它将被跳过,因为它在处理的时候在链接列表中没有依赖关系 >。
The underlying reason (and this is a trait of the gcc/gnu toolchain and not anything to do with nvcc) is that linking dependency lists for static libraries are parsed from left to right by the gnu linker. If you specify a static library before any library which depends on it, it will be skipped because it has no dependencies in the link list at the point in processing when it is first encountered.
这篇关于无法链接到libgfortran.a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!