Creating a Shareable Library

Open PL/I can be used to create shareable libraries (also known as shared libraries) on any supported operating system.

To produce code that can be included in a shareable library, you must ask Open PL/I to produce position-independent code by using the -pic option. Once you have object files generated as position-independent code, you link them into a shareable library using the -so option to ldpli or mfplx.

Note: The -pic option is not required and has no effect for AIX, because all Open PL/I code on AIX is position-independent.

Example: Creating a shareable library using mfplx

File lib1.pli:

library_one: proc;
display('This is library routine one');
end;

File lib2.pli:

library_two: proc;
display('This is library routine two');
end;

File myprog.pli:

dcl library_one entry;
dcl library_two entry;

foo: proc options(main);
call library_one;
call library_two;
end;

Compile and link using commands:

mfplx –pic –so –omylib.so lib1.pli lib2.pli
mfplx –omyprog myprog.pli mylib.so

Example: Using a shared object as a fetchable program

Note: If you intend to use your shared object as a fetchable program, it is important to note that your PL/I proc needs to have the same external name as the shared object or Open PL/I will not be able to load the .so.

File myfetch.pli:

myfetch: proc external(‘myfetch’);
display(‘Inside fetchable function’);
end;

File myprog.pli:

dcl myfetch entry options(fetchable) external(‘myfetch’);

foo: proc options(main);
call myfetch;
end;

Compile and link using commands:

mfplx –pic –so –omyfetch.so myfetch.pli
mfplx –omyprog myprog.pli