Re: Function redefined

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux