This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: inline functions in header file


> Could you attach the .h file?

Yes, that would be a very good start.

> Are you sure 
> 
> #ifndef  __FILENNAME_H
> #define  __FILENNAME_H
> 
> ....
> ....
> inline ....
> inline ....
> ....
> ....
> 
> 
> #endif 
> 
> 
> works properly?


Or maybe try declaring them

static inline return_type function_name( ... )

Quoting from the gcc manual:

       -fkeep-inline-functions
           Even if all calls to a given function are integrated, and the func-
           tion is declared "static", nevertheless output a separate run-time
           callable version of the function.  This switch does not affect
           "extern inline" functions.

I seem to remember looking into this at some point in the past and finding
that unless you declare an inline function static, gcc makes an externally
callable version of the function as well as inlining it everywhere it's
used.  Thus, if the definition of a non-static inline function is given in
a header file, there will be an externally visible copy of the function in
all objects whose source includes that header.  Naturally, if the number of
such objects is greater than one, the linker will complain.  That passage
from the gcc manual would seem to back up this supposition.


So try declaring them static, and if that doesn't help, try declaring them
static *and* compiling with -fno-keep-inline-functions just to make doubly
sure.


                               ------Carl


Oh, even better.  Here's another passage from the gcc manual:

       -finline-functions
           Integrate all simple functions into their callers.  The compiler
           heuristically decides which functions are simple enough to be worth
           integrating in this way.

           If all calls to a given function are integrated, and the function
           is declared "static", then the function is normally not output as
           assembler code in its own right.

Note that 'and the function is declared "static"' qualifier in the second
paragraph.  That's telling.


> On Thursday 03 June 2004 01:56, rainfeng _micro wrote:
> > Dear Mr:
> >      I define an inline function in a header file with "__inline__ void
> > funcname....", and include the header file to two C file .An error went out
> > and the compiler always complain " multiple definition of funcname...".
> >      For example, the function SnGetBufIflag and function SnClearBufIflag
> > are inline functions defined in TouCAN.h, which is included both in
> > TouCAN.c and can_ccp.c,the following is the error message:
> >    can_ccp.o(.text+0x0): In function `SnGetBufIflag':
> >    /cygdrive/f/develop/TouCAN.h:80: multiple definition of `SnGetBufIflag'
> >    toucan.o(.text+0x0):/cygdrive/f/develop/TouCAN.h:80: first defined here
> >    can_ccp.o(.text+0x70): In function `SnClearBufIflag':
> >    /cygdrive/f/develop/TouCAN.h:90: multiple definition of
> > `SnClearBufIflag'
> >    toucan.o(.text+0x70):/cygdrive/f/develop/TouCAN.h:90: first defined here
> >    make: *** [hiwd] Error 1
> >
> > PS: I am using gcc-3.3.2 for powerpc-eabi target
> > Thank you for help
> >
> > _________________________________________________________________
> > ???????????????????????????? MSN Messenger:  http://messenger.msn.com/cn
> >
> >
> > ------
> > Want more information?  See the CrossGCC FAQ,
> > http://www.objsw.com/CrossGCC/ Want to unsubscribe? Send a note to
> > crossgcc-unsubscribe@sources.redhat.com
> 
> ------
> Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
> Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]