This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


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

multiple function definition (was: RE: Use +z or +Z to recompile...)


[ please start a new thread with an appropriate subject line instead
  of replying to other random messages ]

>>>>> "Nagu" == Nagu  <thogiti@usc.edu> writes:

    Nagu> Hi all, I have this problem of linking error using gcc, I
    Nagu> have 4 simple files first.c (where main function is
    Nagu> defined), and myfunc1, myfunc2 and incl.h (which defines
    Nagu> another function called basefunc). When I compile, I get
    Nagu> fatal error saying that multiply defined "basefunc". How to
    Nagu> get rid of this?  Thanks Best nagu

This question is not really a GCC question - it's more a C programming
question. Anyway, you just shouldn't define functions in header files
(except for inline functions). The usual modus operandi is something
like this:

,----[ foo.h ]
| #ifndef FOO_H
| #define FOO_H
| 
| int bar (int);
| 
| #endif /* FOO_H */
`----

,----[ foo.c ]
| #include "foo.h"
| 
| int bar (int x) {
| 	return (x * x);
| }
`----

,----[ main.cc ]
| #include "foo.h"
| 
| int main () {
| 	bar (3);
| 	return 0;
| }
`----

I suggest that you read a good book about programming. Have a look at
http://www.advancedlinuxprogramming.com/. Don't be afraid reading a
book titled "advanced" programming, it just starts with the basics and
is not only applicable for linux.

HTH
-- 
Claudio Bley                                 ASCII ribbon campaign (")
Debian GNU/Linux advocate                     - against HTML email  X 
http://www.cs.uni-magdeburg.de/~bley/                     & vCards / \


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