How to compile shared library on AIX

I have a simple shared library that is currently compiled on Linux using:

gcc -c -fPIC foo.c -o foo.o

gcc -shared -o foo.so foo.o

I need to relay instructions to a colleague for compiling the same on AIX.
I do not know if my colleague will be using gcc on AIX or a native compiler.

Will these gcc instructions also work for AIX? If not, what modifications are necessary? Linux gcc version is 4.4.7
Can anyone provide instructions for same using native AIX compiler? xlC?

Thank you.

Answer

On AIX you can have 3 compilers:

  • GCC
  • newer XL C/C++ Enterprise Edition
  • older VisualAge C++ Professional

For GCC since late 2.x, syntax for creating shared libraries is:

gcc -shared -Wl,-soname,your_soname -o library_name file_list library_list

Example:

gcc -fPIC -g -c -Wall a.c
gcc -fPIC -g -c -Wall b.c
gcc -shared -Wl,-soname,libmystuff.so.1 -o libmystuff.so.1.0.1 a.o b.o -lc

For the above AIX native compilers, see this page for detailed instructions:

http://www.ibm.com/developerworks/aix/library/au-gnu.html

(see section Shared libraries on AIX versus System V systems)

Attribution
Source : Link , Question Author : screwed , Answer Author : Tomasz Klim

Leave a Comment