3

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.

2

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)

  • I'm not sure if ld (linker) of AIX can find a library suffixed with .so, maybe is necessary to rename it or pack it inside an .a file (ar vr libmystuff.a libmystuff.so) – Luciano Oct 27 '16 at 20:12
  • Ohh ! The link provided in the answer explain it. If you use the ld option -brtl, the linker can find libraries suffixed with .so. But without this option, a tip is to rename it or pack it inside an .a file. – Luciano Oct 27 '16 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.