This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [HELP]: Name conflicting in dynamically loading shared libraries
- From: Ian Lance Taylor <iant at google dot com>
- To: Jovi Zhang <bookjovi at gmail dot com>
- Cc: gcc at gcc dot gnu dot org, gcc-help at gcc dot gnu dot org
- Date: Wed, 16 Mar 2011 19:51:03 -0700
- Subject: Re: [HELP]: Name conflicting in dynamically loading shared libraries
- References: <AANLkTin_DfH920TjV543+sLxXsjY+MqQ8m735kLEu-sU@mail.gmail.com>
Jovi Zhang <bookjovi@gmail.com> writes:
> Â ÂI encounter a problem about several .so library linked by a
> problem, when a library A executing call function which source at same
> .so, but strangly it jump to another library B address with same
> function name, then program crash.
>
> Â ÂWhy library A don't find function name in itself address space
> firstly? because compiled using option -fPIC? and how can we avoid
> this problem except change function name?
> Â ÂI know C++ namespace can do this, but it only suit for C++, how
> about C face these problem? Can we use some gcc option help me?
Please never send messages to both gcc@gcc.gnu.org and
gcc-help@gcc.gnu.org. This message is appropriate for
gcc-help@gcc.gnu.org; it is not appropriate for gcc@gcc.gnu.org. Please
keep any followups on gcc-help. Thanks.
You did not mention what operationg system you are using. Assuming it
is GNU/Linux, then this is expected behaviour. Shared libraries on
GNU/Linux and other ELF systems act approximately like static
libraries. When two shared libraries define a symbol with the same
name, the first one encountered is used.
There are a number of ways to change this default behaviour: GCC's
-fvisibility option, GCC's visibility attribute, the linker's -Bsymbolic
option, linker version scripts, etc.
Ian