delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/24/22:46:12

From: "Stefan Viljoen" <rylan AT intekom DOT co DOT za>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problems Linking
Date: Mon, 24 Jul 2000 07:36:47 +0200
Organization: The South African Internet Exchange
Lines: 39
Message-ID: <8lhprh$ki5$1@ctb-nnrp2.saix.net>
References: <397bb60a_3 AT spamkiller DOT newsfeeds DOT com>
NNTP-Posting-Host: pc36-01-p48.nt.saix.net
X-Trace: ctb-nnrp2.saix.net 964455089 21061 155.239.194.48 (24 Jul 2000 16:11:29 GMT)
X-Complaints-To: abuse AT saix DOT net
NNTP-Posting-Date: 24 Jul 2000 16:11:29 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2314.1300
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

23yrold3yrold <cbarry AT pangea DOT ca> wrote in message
news:397bb60a_3 AT spamkiller DOT newsfeeds DOT com...
> Hello. I'm trying to write a game across a few .CPP files, with global
> variables and function prototypes residing in an .H file. If I #include
the
> .H file in one .CPP, the others give "undeclared identifier"errors, and if
I
> #include in all of them, it gives "multiple declaration" errors. All of
> which I can understand; I just want to find a way to get it all to work
> together. Thanks muchly in advance.

I handle it like this:

In the .H file, define the variable as extern:

extern int myvar;

Then, declare myvar in ONE module only:

int myvar = 0;

Then include the .H file in all modules - you'll have global access to the
variable, it will link without errors, even though it is actually declared
in one module only it is listed as extern in the .H file. Then, include this
.H file in all your modules.

Hope this helped!

Stefan Viljoen


--
Starwars Forever!!!

mailto:Stefan_Viljoen AT excite DOT com
http://home.intekom.com/rylan/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019