czos

How to compile shared C library on zOS


I have several source files in C with one function per file. I have to compile it to shared library on z/OS using xlc compiler.

I'm compiling C files with

xlc -c -O2 -o o/func1.o func1.c

later on I create lib file with

xlc -o library.o o/*.o

I wonder if this is the correct way to create shared library in Z/OS ?

Does anyone has got more experience and help me out with it ?


Solution

  • Posting on behalf of very knowledgeable developer.

    On z/OS, shared libraries are called DLL’s and you need to specify the DLL option to generate one. Here is an example of how to do so and how to create an application using the DLL. Note that you still will need to export the functions (and data) you want other modules to access. This can be done either through the #pragma export directive (https://www.ibm.com/docs/en/zos/3.1.0?topic=descriptions-pragma-export) or the EXPORTALL compiler option (https://www.ibm.com/docs/en/zos/3.1.0?topic=options-exportall-noexportall) for example. Details can be found here: https://www.ibm.com/docs/en/zos/3.1.0?topic=dlls-building-dll-application

    xlc library.c -qdll -Wl,dll -o library.dll # Creates the DLL

    xlc main.c library.x -qdll -o runme # Create the application that will use the DLL. The .x file is the sidedeck created by the first command.

    You can use the LIBPATH environment variable to point to the directory of the DLL when you run the application.