Reputation: 855
I need to statically link my application which uses libraries like csparse, gsl, pthread, lapack and blas. The last two need also libgfortran. So my command is
gcc -o main bunch_of_object_files.o -fopenmp -static -lcsparse -lgsl -lgslcblas -lpthread -llapack -lblas -lm -lgfortran
and the output is
/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
but it works if I link using gfortran instead of gcc. Why?
Upvotes: 1
Views: 3016
Reputation: 74485
Put -lm
after -lgfortran
. When static linking the ordering is important.
Upvotes: 4