1

我需要静态链接我的应用程序,它使用 csparse、gsl、pthread、lapack 和 blas 等库。最后两个还需要 libgfortran。所以我的命令是

gcc -o main bunch_of_object_files.o -fopenmp -static -lcsparse -lgsl -lgslcblas -lpthread -llapack -lblas -lm -lgfortran

输出是

/usr/lib/gcc/x86_64-linux-gnu/4.4.3/libgfortran.a(fpu.o): In function `_gfortrani_set_fpu':
(.text+0xa): undefined reference to `fedisableexcept'
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/libgfortran.a(fpu.o): In function `_gfortrani_set_fpu':
(.text+0x56): undefined reference to `feenableexcept'
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/libgfortran.a(fpu.o): In function `_gfortrani_set_fpu':
(.text+0x6e): undefined reference to `feenableexcept'
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/libgfortran.a(fpu.o): In function `_gfortrani_set_fpu':
(.text+0x86): undefined reference to `feenableexcept'
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/libgfortran.a(fpu.o): In function `_gfortrani_set_fpu':
(.text+0xb6): undefined reference to `feenableexcept'
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/libgfortran.a(fpu.o): In function `_gfortrani_set_fpu':
(.text+0x4a): undefined reference to `feenableexcept'
collect2: ld returned 1 exit status

但如果我使用 gfortran 而不是 gcc 链接,它会起作用。为什么?

4

1 回答 1

4

放在-lm后面-lgfortran。当静态链接时,排序很重要。

于 2012-05-07T14:41:34.097 回答