Results 1 to 1 of 1
I am updating a suite of programs that previously used static libraries to use shared libraries instead and have hit a problem which makes me wonder if I can use ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 03-17-2004 #1
- Join Date
- Mar 2004
Shared library misery
The problem is as follows: I create shared libary lib1.so, which uses a function foo() from another library lib2.so (in a constructor function as it happens). Then I link various programs against lib1.so
Usually they work fine. But if a program contains a global function also called foo() I get a segmentation violation : my lib1.so now tries to use the unrelated foo() from program1 instead of the one in lib2.so
This is terrible and something that could never happen when creating a Windows DLL.
Is there a soluition, or do I just have to change any problem names as I come across them.
I am linking lib1.so like this
gcc -Wl,-z,defs,-Bsymbolic -shared -o lib1.so objs lib2.so lib1.def -lm -lc
lib1.def contains linker script to version all my symbols and hide all the symbols apart from the ones I explicityly want to export.
-Bsymbolic sounds as though it should do what I want but it is only good for foo() contained in objs, not foo() imported from another library.
-Bgroup also looked promising but appears to have no effect
-z defs does not seem to work properly either - if I omit -lm -lc from the link I do not get any warnings about undefined symbols for the libc symbols I am using.
I am using gcc 2.95 (not gcc 3.x so I can run on old distros) and binutils 2.14
I'd be grateful for any assistance, but please don't tell me I should be using libtool or something - my make file is intended for use on platforms from Windows CE through to HPUX and I only use gcc on Linux