| Author |
Problem with shared code under linux
|
|
| John Smith 2005-01-26, 6:02 pm |
| Under linux (Redhat 9.0 x86) I'm trying to build a shared library and a
program which uses it. Both files has some shared code (lets call the C++
class foo) between them to read configuration files. In short it works in
this way:
1. User supplies a config file to executable.
2. Program uses foo class to read config file.
3. Program passes execution to shared library with information from read
file.
4. Library reads another configuration file.
5. Programs does their action....
The big problem I have is that the overlap of code seems to cause problems.
I've done the following tests to come to this result:
If both files are compiled with -O2 and no symbols stripped step 4 fails. I
added a printf() to foo class and only recompiled the shared library and it
seems the code doesn't even get called. I can't tell why because it should.
If I compile either of them with no optimization and debug symbol (-g) it
works.
The shared library probably exports something I don't want it to export.
Under Mac OSX I have a switch for gcc called -exported_symbols_list which
takes a file that has the exports I want to have for the file. For Linux
version of gcc I can't see the same option. If I could select what I want to
export it would probably solve the problems.
Thanks in advance.
-- John
| |
| Gianni Mariani 2005-01-26, 6:02 pm |
| John Smith wrote:
...
>
> If both files are compiled with -O2 and no symbols stripped step 4 fails. I
> added a printf() to foo class and only recompiled the shared library and it
> seems the code doesn't even get called. I can't tell why because it should.
Does a version of foo get linked into your library ?
Are your methods of foo inlined ?
| |
| Paul Pluzhnikov 2005-01-26, 6:02 pm |
| "John Smith" <john.smith@x-formation.com> writes:
> Under Mac OSX I have a switch for gcc called -exported_symbols_list which
> takes a file that has the exports I want to have for the file. For Linux
> version of gcc I can't see the same option. If I could select what I want to
> export it would probably solve the problems.
On Linux you can control exported symbols with a version script:
$ cat Versions
Foo {
global:
function1;
function2;
function3;
local:
*;
};
$ gcc -shared -fPIC -o foo.so foo.c -Wl,--version-script,Versions
Try "info ld" -> "Linker scripts" -> "VERSION"
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
| |
| John Smith 2005-01-26, 6:02 pm |
| > Does a version of foo get linked into your library ?
>
Yes. Foo is a C++ class. It gets compiled and linked to both executable and
library. I think thats the problem, because it seems the library version of
foo does not get called apropriately. I personally think this has something
to do with exports/imports of the two files.
The question just is why(?).
The thing I don't understand is why it works when one of the file (either of
them) are compiled in debug mode. Does the linker change the exported names
of functions if that is the case?
> Are your methods of foo inlined ?
No. I was in doubt but I double checked now and it's not the case.
-- John
|
|
|
|