Force symbol inclusion in .a library
Dave W
dave-gmane@bfnet.com
Tue Oct 16 19:05:00 GMT 2007
My buddy is porting some code from windows to linux, and he asked me this
ar question that I couldn't answer. Does anyone have any ideas?
Quoth my friend:
I have two 'libraries' XModule.o and XLoader.o.
XModule.o gets linked into the modules and provides a
function: extern "C" GlueFunctionThatPutsMagicPointer(void
*) { blah... }
Then when a module gets loaded the client ends up doing:
pLib = dlopen("libWhateverModule.so"); pFunc = dlsym(pLib,
"GlueFunctionThatPutsMagicPointer"); (*pFunc)(pointer);
You can see in Makefile.XModule that I stick (cp) XModule.o
into the libs directory and then when modules link (see
Makefile.IXFrameBuffer) I include XModule.o on the link
line directly. It works fine, but what I want is to create
a static library in Makefile.XModule as follows: ar crs
libXModule.a XModule.o
which works, but when libXModule.a is linked in with a
module shared lib, the module shared lib doesn't get the
symbol GlueFunctionThatPutsMagicPointer, because it is not
statically referenced by the module itself. So I just link
the module against the .o file to make sure the symbol is
in there. That is ok, but I kind of wanted it to be a .a
not a .o. Not critical but if you know how to force the
symbol in - thought I'd ask.
Works in windows because on windows the function is
declared extern "C" _declspec(dllexport) Glue(void *);
which forces the linker to include the symbol because it is
marked for dll exporting.
More information about the Binutils
mailing list