我试图了解如何在Linux下动态创建和链接Fortran中的共享库.
我有两个文件:第一个liblol.f90,看起来像这样:
subroutine func()
print*, 'lol!'
end subroutine func
Run Code Online (Sandbox Code Playgroud)
我用它编译它 gfortran -shared -fPIC -o liblol.so liblol.f90
第二个文件main.f90看起来像这样:
program main
call func()
end program main
Run Code Online (Sandbox Code Playgroud)
当我现在尝试使用该命令编译时gfortran -L. -llol main.f90 -o main,我收到以下错误:
/tmp/ccIUIhcE.o: In function `MAIN__':
main.f90:(.text+0xa): undefined reference to `func_'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我不明白为什么它说"未定义的引用",因为输出nm -D liblol.so给了我这个:
w _Jv_RegisterClasses
0000000000201028 A __bss_start
w __cxa_finalize
w __gmon_start__
0000000000201028 A _edata
0000000000201038 A _end
0000000000000778 T _fini
U _gfortran_st_write
U _gfortran_st_write_done
U _gfortran_transfer_character_write …Run Code Online (Sandbox Code Playgroud)