我需要静态链接我使用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链接它会起作用。为什么呢?
答案 0 :(得分:4)
将-lm
放在-lgfortran
之后。静态链接时,顺序很重要。