This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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(""); 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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]