Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29246 Discussions

Generating shared libraries and privacy

eliosh
Beginner
478 Views

Hello,

What is the correct way to generate a shared library from a module?

I currently use ifort -share -fpic mymod.f90

Actually, it works as expected, however there is a small question regarding private variables. As far as I see all variables are exported in the generated library. Which means they all are accessible after such a library is loaded. I would expect private variables not to be exported. Am I missing something?

Thank you.

0 Kudos
3 Replies
Steven_L_Intel1
Employee
478 Views

See my reply to your post in comp.lang.fortran - quoted here.

The private accessibility applies only to the Fortran language view of the module as to their accessibility when the module is USEd. A global/exported symbol may still be required in order for the program to function. For example, a generic interface may have the generic name public but the specific names private. The compiler still needs to be able to reference the specific names for linking, so they need to be visible in the shared library. You just can't reference them in the source.

It's also possible to have the name be inaccessible in one part of the program and accessible in another.

0 Kudos
eliosh
Beginner
478 Views

Steve, thank you very much for your answer.

I have another small question. When I compile a module (say testmod) with ifort there is text segment (code) in the object file named testmod._ . Can you explain what function is this. Thank you.

0 Kudos
Steven_L_Intel1
Employee
478 Views
It's just an empty routine put there to define a global symbol corresponding to the module name so that the linker will complain if you have two objects with the same module name.
0 Kudos
Reply