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/

_______________________________________________
Help-gplusplus mailing list
Help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to