public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Claudio Bley" <bley@cs.uni-magdeburg.de>
To: Nagu <thogiti@usc.edu>
Cc: gcc-help@gcc.gnu.org
Subject: multiple function definition (was: RE: Use +z or +Z to recompile...)
Date: Tue, 22 Oct 2002 02:27:00 -0000	[thread overview]
Message-ID: <15797.6654.815747.575237@wh2-19.st.uni-magdeburg.de> (raw)
In-Reply-To: <000501c27965$4b1c0320$f70b7d80@drb324>

[ 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 / \

  reply	other threads:[~2002-10-22  9:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-21 10:47 Use +z or +Z to recompile Venkatakrishnan, V
2002-10-21 10:55 ` Jeff Law
2002-10-21 17:50   ` Nagu
2002-10-22  2:27     ` Claudio Bley [this message]
2002-10-23  3:45     ` Andrea Bocci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15797.6654.815747.575237@wh2-19.st.uni-magdeburg.de \
    --to=bley@cs.uni-magdeburg.de \
    --cc=gcc-help@gcc.gnu.org \
    --cc=thogiti@usc.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).