From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12542 invoked by alias); 22 Oct 2002 09:27:09 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 12475 invoked from network); 22 Oct 2002 09:27:06 -0000 Received: from unknown (HELO wh2-19.st.uni-magdeburg.de) (141.44.162.19) by sources.redhat.com with SMTP; 22 Oct 2002 09:27:06 -0000 Received: by wh2-19.st.uni-magdeburg.de (Postfix, from userid 1000) id CD64C90F60; Tue, 22 Oct 2002 11:27:28 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15797.6654.815747.575237@wh2-19.st.uni-magdeburg.de> Date: Tue, 22 Oct 2002 02:27:00 -0000 From: "Claudio Bley" To: Nagu Cc: gcc-help@gcc.gnu.org Subject: multiple function definition (was: RE: Use +z or +Z to recompile...) In-Reply-To: <000501c27965$4b1c0320$f70b7d80@drb324> References: <200210211803.g9LI3LSF032715@porcupine.cygnus.com> <000501c27965$4b1c0320$f70b7d80@drb324> X-SW-Source: 2002-10/txt/msg00264.txt.bz2 [ please start a new thread with an appropriate subject line instead of replying to other random messages ] >>>>> "Nagu" == Nagu 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 / \