Dynamic Loading of a shared object library

Dynamic Loading of a shared object library

Hi

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...

Abhi

5 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di Steve Lionel (Intel)

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.

http://tldp.org/HOWTO/Program-Library-HOWTO/dl-libraries.html

Steve

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.

Sincerely

Abhijit

 

Allegati: 

AllegatoDimensione
Download library.f90161 byte
Download 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)

Ritratto di Steve Lionel (Intel)

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.

Steve

Accedere per lasciare un commento.