0

I am attempting to compile a simple C program into a .so file using the cc compiler on an AIX system. The program is:

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("Hello, world\n");

    return 0;
}

First, I created a .o file using the following:

cc -c -fPIC hello_world.c -o hello_world.o

This seems to work, but then when I attempt to create the .so file using:

cc hello_world.o -shared -o hello_world.so

I get the following errors:

ld: 0706-012 The -h flag is not recognized.

ld: 0706-012 The -a flag is not recognized.

Can anyone tell me what might be causing these errors?

  • 1
    Find out what exact compiler you're using and look at its docs. If it is xLC (IBM compiler), the docs are easy to find. – Mat Dec 08 '21 at 17:10
  • that `-shared` option looks suspicious. you can use `man cc` to see the documentation. – tromgy Dec 08 '21 at 17:19
  • Looks like the compiler is treating `-shared` as a sequence of short options: e.g. `-s -h -a -r -e -d` . Try invoking the linker directly: `ld hello_world.o -shared -o hello_world.so` . – G.M. Dec 08 '21 at 17:43
  • Ok, it looks like it was the -shared option that was causing the error. When I take it out I no longer get any errors, but it was this option that was telling the compiler to make the shared object. I looked in the documentation as mentioned above and found the -G option, but this still does not appear to create a proper .so file, so the question now is what are the options that I need to use to create the .so file from the .o file? – ramjimg Dec 08 '21 at 18:54
  • 1
    https://www.ibm.com/docs/en/xl-c-aix/13.1.0?topic=library-compiling-shared Note: function `main` should not appear in a shared object. Use some other name such as `testfun1`. – Zsigmond Lőrinczy Dec 09 '21 at 04:41

0 Answers0