This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Force symbol inclusion in .a library
- From: Dave W <dave-gmane at bfnet dot com>
- To: binutils at sources dot redhat dot com
- Date: Tue, 16 Oct 2007 18:13:29 +0000 (UTC)
- Subject: Force symbol inclusion in .a library
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.