Dynamic Loading of a shared object library

Dynamic Loading of a shared object library


Can someone point me to documentation and example of dynamic (explicit) loading of a shared-object library on Linux? (I do understand that this is an age-old question.)

I know how this is done on Windows i.e. using LoadLibrary and GetProcAddress. I am looking for an equivalent of this on Linux. { In some search results, I find that wrapping of dlopen and dlsym has been mentioned. Is that the only way? }

The IVF window's installation has a sample for dynamic loading of a DLL (which shows how to use LoadLibrary and GeProcAddress with kernel32 module). But there is no such sample for the Linux install.

And Intel Premier Support's answer is "read creating shared object library" chapter in the documentation...


5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Here's the Linux equivalent. The example is in C but you should be able to figure it out. The C interoperability features will help.


Retired 12/31/2016

Hi Steve

Actually, I did this as in the files attached. One issue I have is how I can avoid namecase decoration. That is, on line 65 from Test.f90, I have to specify "somemethod_". I am wondering how I can avoid the lowercase and underscore.  I can use the attributes and alias in Library but is there a way I can do it from the Test program.

I used:

ifort -shared -fPIC Library.f90 followed by ifort Test.f90.

 As a side note, I see that the library created has a some randomName.so when I was expecting this to be Library.so. I manually renamed it to MyLib.so to work with my test program.





Downloadapplication/octet-stream library.f90161 bytes
Downloadapplication/octet-stream test.f902.31 KB

How about in library.f90 doing the following:

      Subroutine SomeMethod(j) BIND(C,NAME="somemethod")

Thus allowing use of the lowercase name without underscore at line 65 of test.f90.

You may name the shared library using -o option and name such to also leverage the convenience of the linker -l option in this way:

ifort -shared -fpic -o libMylib.so library.f90
ifort test.f90 -L. -lMylib

(The second ifort command assumes you place the resulting libMylib.so in the current working directory)

With BIND(C), you wouldn't need to use an all-downcased name as that's the default. Any underscore decoration would be whatever C uses.

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today