- c文件
#include<stdio.h>
void show_(float *);
int main(){
float a=100;
show_(&a);
}
- f90文件
subroutine show(a)
real :: a
print*, a
return
end subroutine show
- Makefile
test : test.c show.f90
gfortran -c show.f90 -o show.o
gcc -c test.c -o test.o
gcc -o test.exe test.o show.o
結果報錯
show.o:show.f90:(.text+0x3f): undefined reference to `_gfortran_st_write'
show.o:show.f90:(.text+0x58): undefined reference to `_gfortran_transfer_real_write'
show.o:show.f90:(.text+0x64): undefined reference to `_gfortran_st_write_done'
網上查到是少了靜態鏈接庫,查到的那個博客加了一大堆庫,大概用不到那麼多吧。看報錯,少的大概是gfortran
庫?不管了試試看
- Makefile (
-lgfortran
似乎只能放在.o
文件後面,否則還是報前面一樣的錯誤)
test : test.c show.f90
gfortran -c show.f90 -o show.o
gcc -c test.c -o test.o
gcc -o test.exe test.o show.o -lgfortran
又報新的錯誤
C:/MyProgram/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/libgfortran.a(write.o):(.text$get_precision+0x160): undefined reference to `quadmath_snprintf'
C:/MyProgram/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/libgfortran.a(write.o):(.text$get_float_string+0x16b): undefined reference to `quadmath_snprintf'
C:/MyProgram/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/libgfortran.a(write.o):(.text$get_float_string+0xa2f): undefined reference to `quadmath_snprintf'
C:/MyProgram/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/libgfortran.a(write.o):(.text$get_float_string+0x162c): undefined reference to `quadmath_snprintf'
C:/MyProgram/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/libgfortran.a(write.o):(.text$get_float_string+0x170a): undefined reference to `quadmath_snprintf'
我似乎發現了某種規律
- Makefile
test : test.c show.f90
gfortran -c show.f90 -o show.o
gcc -c test.c -o test.o
gcc -o test.exe test.o show.o -lgfortran -lquadmath
ok,編譯通過。所以是不是看報錯加庫就可以了呢,待以後驗證吧