This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Function redefined
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: Amit Choudhary <amit2030 at yahoo dot com>, gcc-help at gcc dot gnu dot org
- Date: Fri, 20 Aug 2004 06:58:27 -0500
- Subject: Re: Function redefined
- References: <20040820064908.2664.qmail@web41114.mail.yahoo.com>
Hi Amit,
>1. Doesn't gcc find the definition twice and shouldn't it report the error?
No. Definitions in your object code supersede definitions in archive
libraries and shared object libraries.
If not careful, antics and hilarity can ensue.
What I found was that it uses the first definition found.
>2. Was it always like this or sometime during the course of evolution of
compilers, it was decided that the first definition would be used?
It's been like that as long as I'm aware. But I've only been programming
for 28 years.
Maybe in the good old days before I started programming it was
different. Or maybe it's different on platforms other than the ones I'm
familiar with.
>3. Or, since it is compiled with dynamic library, it is behaving that way?
Yes, dynamic libraries (SSO) behave that way, although DSO's do not.
SSO - static shared object
DSO - dynamic shared object
You can list out your executable's SSO's using the ldd command.
DSO's explicitly use the dlopen and manually match symbols up from the
shared object library.
You could use a DSO to access the atoi function in the library, even if you
have an SSO or executable that has defined a different atoi function.
>4. Would compiling it with static C library (libc.a) would give me a
"function redefined" error?
No. Your object code supersedes both shared object libraries and archive
libraries.
(There are tricks to make that not happen, but you'd have to take measures
and fiddle with some of the compiler/linker options.)
HTH,
--Eljay