gcc 2.96, inlining and multiple def. linker errors
Hi all,
I''m running into a problem with linking my code. I''m using Redhat and gcc 2.96. I have a few functions that I have defined as inline i.e.
============================================================
*.h
__inline my_memcpy(u16* dest, const u16* src, u32 size) { my_memmove(dest, src, size); }
============================================================
something like that. my_memcpy is used in multiple files in my project. Everything compiles and links fine in Visual Studio. Everything compiles fine on linux but when I try to link I get a my_memcpy has multiple definitions error. I have searched for this error but can''t find any cases that match the one I''m running into. Most of them have to do with templates or the fix that was offered to the person doesn''t work for me.
Is inlining done differently in gcc?
Is there a link option that I need to use to make inlining work?
Any help would be much appreciated.
You are using C++, right? If so, it''s spelled
inline
, not __inline
. It''s the same for both GCC and MSVC.
I''m using C and yes, I have tried the different variations of the inline keyword that I could find. Still, no luck. :/
Ah. C is a different matter. Then you do need C99 support or a compiler extension. You should try a recent version of GCC; 3.3.1 is the latest release (there never were a 2.96 release, it's a development version patched by Red Hat).
Failing that, I believe
[edited by - spock on September 15, 2003 2:22:55 PM]
Failing that, I believe
__inline__
is the compiler extension to use for GCC. [edited by - spock on September 15, 2003 2:22:55 PM]
Thanks for your help spock!
Unfortunately I can''t use the newest version of gcc for compatibility reasons (another groups software won''t be able to use my library if i compile with gcc 3.3).
Unfortunately I can''t use the newest version of gcc for compatibility reasons (another groups software won''t be able to use my library if i compile with gcc 3.3).
If you must use the 2.96 compiler at least make sure it''s the last Red Hat revision; some of the earlier ones were horribly broken. Avoid it if at all possible.
Also be aware that like any compiler extension, the semantics of
Also be aware that like any compiler extension, the semantics of
__inline__
may not be what you expect.
Thanks again spock for trying to help me. I just read a bit about 2.96 (http://gcc.gnu.org/gcc-2.96.html) and i have to say i''m at a loss for words as to why anyone would take this particular build into consideration.
I''m just gonna upgrade to the most recent version of redhat and as well as the most recent version of gcc.
Thanks!
I''m just gonna upgrade to the most recent version of redhat and as well as the most recent version of gcc.
Thanks!
September 16, 2003 05:42 AM
quote: Original post by xtrmntr
Unfortunately I can''t use the newest version of gcc for compatibility reasons (another groups software won''t be able to use my library if i compile with gcc 3.3).
Sure they can, if you are (as you say you are but you seem a little confused on the matter) using C. It is only the C++ ABI that has changed, not the C ABI.
ok, so I upgraded my stuff to rehat 9 and gcc 3.2.2 but it''s still giving me the same error. Very easy to reproduce and only causes a problem when linking using gcc ie. visual studio, metroworks, ARM, etc. all work fine).
foo.h
test.h
test.c
main.c
compiling this code is fine.
linking the object files will produce the following error:
In function ''Add'' :
: multiple definition of ''dd''
foo.o: first defined here
What am I doing wrong if this works on every other compiler I''ve tried it on?
foo.h
#ifndef FOO_H#define FOO_Hinline int Add(int a, int b){ return a+b;}#endif
test.h
#ifndef TEST_H#define TEST_Hint Double(int a);#endif
test.c
#include "foo.h"#include "test.h"int Double(int a){ return Add(a, a);}
main.c
#include "test.h"#include "foo.h"int main(int argc, char* argv[]){ Double(10, 10); return 0;}
compiling this code is fine.
linking the object files will produce the following error:
In function ''Add'' :
: multiple definition of ''dd''
foo.o: first defined here
What am I doing wrong if this works on every other compiler I''ve tried it on?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement