views:

444

answers:

1

I'm running Solaris, so it's possible that this is specific to running GCC on Solaris. If I use GCC to generate a shared object, and then run nm on it to see undefined symbols, there will always be a reference to main:

[624]     |         0|       0|NOTY |GLOB |0    |UNDEF  |main

If I manually generate the same shared object using ld, the reference to main doesn't exist. If I run nm on the system libraries in /usr/lib, none of them appear to have references to main. Only shared libraries I compile myself with GCC.

Apps compiled against these shared libraries work fine and without errors. But I still don't understand why the reference to main is there in the first place. Any clues?

+4  A: 

You forgot the -shared option in your gcc link command line.

EDIT: and you forgot -fPIC option on your compile command line (which is causing all the relocation errors at link time).

If you still get relocation errors with -fPIC on all compile lines, then you should rebuild all the archive libraries which you link in (libtoast_datetime, libtoast_assert, etc.) with -fPIC as well.

Pierre Bourdon
I thought that's what the -G accomplished? Anyway, trying with "-shared" I get a million linker errors about Unwind_resume missing in boost. If I try again with "-shared-libgcc" then I get no errors, but the .so has a reference to main again O_o
Joseph Garvin
Also strangely they're text relocation errors, not undefined reference errors.
Joseph Garvin
It turns out you were right, my testing just wasn't working because I don't write the link line myself, my make tool does, so I'd been copy and pasting the link line it'd generated and tweaking it, and I accidentally was using a link line from a shared build in a static sandbox ;pSeparate question -- why has this worked in the past? All the shared objects here have been built with -fPIC in the past, but *not* with -shared and have worked fine. This didn't become an issue until I started work to make linking more precise (only pulling in exactly what's needed).
Joseph Garvin