Bug in g++ 4.1.2 when using inline function definied in cpp file but declared in h file

Jim Wilson wilson@specifix.com
Fri Mar 23 00:46:00 GMT 2007


We don't track bugs reported via email.  If you want to make sure you 
get an answer, use the bugzilla database instead.  This doesn't seem to 
be a gcc bug though.

In C++, the inline keyword is similar to what "static inline" means in 
GNU C, i.e. only emit the function if it is used.  Since there is no use 
of the function in a.cpp, gcc does not emit it.  You can see this if you 
compile a.cpp with -S and look at the assembler output.

You can fix this by deleting the use of the inline keyword.  Or you can 
fix it by putting the inline function definition into the a.h file 
instead of the a.cpp file.  This way it will be visible in main.cpp when 
we call it, and then gcc will emit it.

Or you can fix it by using pragma implementation and pragma interface as 
you discovered.

I'm not a C++ expert.  There may also be other ways to fix this.
-- 
Jim Wilson, GNU Tools Support, http://www.specifix.com



More information about the Gcc-bugs mailing list