| subroutine
ex(i) integer i i=i+1 return end |
| g95
-c ex.f90 g95 -shared -mrtd -o ex.dll ex.o |
| -c | Compile only, producing the object file ex.o |
| -o | Names the output file ex.dll |
| -shared | Creates the dll |
| -mrtd | Sets the calling convention to stdcall |
| $ cat > mytest.f90 ! A test program to call ex.dll integer :: i i = 6 call ex(i) print *, i end $ g95 -o mytest mytest.f90 -L. ex.dll $ mytest 7 $ |
| subroutine
dll1 real :: arr(2,2) call random_number(arr) print*,arr ! call dll2 call dynload end subroutine dll1 |
| subroutine
dll2 integer :: n=10 call sub1(n) contains subroutine sub1(n) real :: arr(n,n) print*,'here' call random_number(arr) print*,'done' end subroutine sub1 end subroutine dll2 |
| program
m call dll1 end program m |
| //
load.c - Cygwin version #include <dlfcn.h> #include <stdio.h> #include <errno.h> void dynload_() { void (*Function)(),*Handle; Handle = dlopen( "dll2.dll", RTLD_NOW ); if ( Handle == NULL ) { fprintf( stderr, "can't load: %s\n", dlerror() ); exit(0); } Function = (void(*)())dlsym( Handle,"dll2_" ); if ( Function == NULL ) { fprintf( stderr, "can't find function dll2_: %s\n", dlerror() ); exit(0); } (*Function)(); } |
| //
load.c - MinGW version #include <windows.h> void dynload_() { typedef void (*pfunc)(); HANDLE hdll; pfunc sub1; hdll = LoadLibrary("dll2.dll"); sub1 = (pfunc)GetProcAddress(hdll, "dll2_"); sub1(); return; } |
| gcc
-c load.c g95 -shared -Wl,--enable-auto-import -o dll1.dll dll1.f90 load.o g95 -shared -Wl,--enable-auto-import -o dll2.dll dll2.f90 dll1.dll g95 -o main main.f90 /lib/g95main.o -L. dll1.dll |
| $
main.exe 0.8784881 0.18738759 0.47982866 0.24209005 here done $ |
| objdump: | Display information from object files |
| objcopy |
Copy and translate
object files |
| nm: |
List symbols from object files |
| dlltool: |
Create files needed to build and use dlls |
| strip: | Discard debug symbols |
| ar |
Create, modify, and
extract from archives |
| ranlib |
Generate index to
archive contents |