help-gplusplus
[Top][All Lists]
Advanced

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

Re: "Ignoring second definition" warning


From: Ulrich Eckhardt
Subject: Re: "Ignoring second definition" warning
Date: Fri, 23 Sep 2005 17:42:09 +0200
User-agent: KNode/0.8.2

mrstephengross wrote:
> =======================================
> temp.h: inline int foo() { return 0; }
> a.cpp: #include "temp.h"
>        int a() { return foo(); }
> b.cpp: #include "temp.h"
>        int b() { return foo(); }
> =======================================
> 
[...]
> The object files get built fine. Now I want to archive them together
> into a single .a :
[..]
> And I get a warning about how ar is ignoring the second definition of
> 'foo'. It would appear that the compiler ignored the 'inline' specifier
> and preserved 'foo' as a symbol in each object file.

Even an inline function must generate an out-of-line definition, after all
some other file might want to use it and only have a declaration.

> I've tried to force gcc to truly inline the functions by playing around
> with gcc's options (such as -finline-size). So far I've been
> unsuccessful. 

Yes, anything else would be wrong for above reasons. You might be able to
force it to be inline with some attributes added to the function though.

> Any ideas? 

Yes, make it a static function. A static function has internal linkage, so
the compiler can know all cases where the function is used and avoid
generating an out-of-line definition if it's not needed.

Uli

-- 
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]