I am trying to understand how to dynamically create and link a shared library in Fortran under Linux.
I have two files: the first liblol.f90,, looks like this:
subroutine func()
print*, 'lol!'
end subroutine func
I will compile it with gfortran -shared -fPIC -o liblol.so liblol.f90
The second file is main.f90as follows:
program main
call func()
end program main
When I try to compile this with the command gfortran -L. -llol main.f90 -o main, I get the following error:
/tmp/ccIUIhcE.o: In function `MAIN__':
main.f90:(.text+0xa): undefined reference to `func_'
collect2: ld returned 1 exit status
I don’t understand why it says “undefined link” as the output nm -D liblol.sogives me this:
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
0000000000000598 T _init
00000000000006cc T func_
Is any other parameter required?
source
share