我想在Windows上为Fortran项目创建DLL(实际上是Fortran + C).当dll依赖于另一个时,我遇到了麻烦,我在Linux上遇到了麻烦.
这是一个简短的例子:
文件dll1.f90
module dll1
implicit none
contains
subroutine test1
write(*,*) "test1 ok"
end subroutine
end module
Run Code Online (Sandbox Code Playgroud)
文件dll2.f90
module dll2
use dll1,only : test1
implicit none
contains
subroutine test2
call test1
end subroutine
end module
Run Code Online (Sandbox Code Playgroud)
文件main.f90
program main
use dll2, only : test2
implicit none
call test2
end program
Run Code Online (Sandbox Code Playgroud)
Linux命令(文件run.bash)
gfortran -shared -fPIC -o libdll1.so dll1.f90
gfortran -shared -fPIC -o libdll2.so dll2.f90
gfortran -o main.exe main.f90 -I. -L. -ldll2 -ldll1
export LD_LIBRARY_PATH="./"
./main.exe
Run Code Online (Sandbox Code Playgroud)
Windows命令(文件run.bat)
gfortran -shared -fPIC -o …Run Code Online (Sandbox Code Playgroud)