Module in statically-linked object

Dear PGI experts,

I want to create (with FORTRAN) a shared object files, lets say myso.so. In this .so I have one module file, modso.f, and one ‘subroutine file’, subso.f.

I also have a statically-linked object (in FORTRAN again), lets say mya.a with 3 subroutine files, and 2 module files, moda1.f and moda2.f.

At the linking of myso.so, I include the mya.a, and of course the modso.o, subso.o. In the modso.f and subso.f, I have the USE statement for using the moda1.f and moda2.f modules that are in mya.a.

What’s my problem is: When I open (during runtime of main program) the myso.so library (using the command dlopen(myso.so, RTLD_LAZY)), I get this error returning from dlerror(): myso.so: undefined symbol: moda1_

So in other words, it seems that the .so library can’t see the modules in the .a library. In compiling and linking phase I didn’t get any error/warning.

Thanks in advanced.

Hi eliascm,

By default, ld wont include symbols from an archive (i.e .a static libraries) when creating shared libraries. You can add “–whole-archive” to get ld to do this but be careful since any system libraries included on the link will also be added. If you are using pgfortran to create the shared library, use “-Wl,–whole-archive” before the archives you want to add and “”-Wl,–no-whole-archive" just after it. This will cause only these archives to be added.

For example:

pgfortran -shared -o libsum.so -Wl,--whole-archive libsum.a -Wl,--no-whole-archive common.o

If you’re curious, you can add “-v” (verbose) to see the linker command the pgfortran driver invokes to create the shared library.

Hope this helps,
Mat