Multiple definitions - slightly not SDL related

as this is the only mailing list i subscribe to i’m posting this here,

i have some code for a game i am working on where there is a keys.c that
contains the functions for checking for key events, keys.h contains integer
definitions to hold key presses, when i compile, the compiler i am using on
windows ( devc++ (mingw) ) spits back at me i have multiple definitons, in
main.c i need to #include keys.h for quit and mouse stuff, so it says i have
multiple defintions in keys.c and main.c yet i have another program that does
not do this, also when i try using riscos gcc with exactly the same source code
it gives me no warnings or errors, help!

i have another game i am working on that is pretty much the same setup, but it
dosnt complain!

i used to be a single file code writer, but recently i’ve been trying to make my
code properly modular, so i am stil stabbing in the dark a bit, if anyone can
give me any advice as to what i may or may not be doing that is causing the
problems thanks.–

Nice.


This message was sent using IMP, the Internet Messaging Program.

Have you extern the variables?

So in keys.c you have:
int keyPressed;

and in keys.h you have
extern int keyPressed;

Including keys.h in your main.c file will let you access keyPressed (as it’s a now a global variable)

Ed> ----- Original Message -----

From: neil@cloudsprinter.com (Neil White)
To: sdl at libsdl.org
Sent: Saturday, 20 January, 2007 2:56:38 PM
Subject: [SDL] multiple definitions - slightly not SDL related

as this is the only mailing list i subscribe to i’m posting this here,

i have some code for a game i am working on where there is a keys.c that
contains the functions for checking for key events, keys.h contains integer
definitions to hold key presses, when i compile, the compiler i am using on
windows ( devc++ (mingw) ) spits back at me i have multiple definitons, in
main.c i need to #include keys.h for quit and mouse stuff, so it says i have
multiple defintions in keys.c and main.c yet i have another program that does
not do this, also when i try using riscos gcc with exactly the same source code
it gives me no warnings or errors, help!

i have another game i am working on that is pretty much the same setup, but it
dosnt complain!

i used to be a single file code writer, but recently i’ve been trying to make my
code properly modular, so i am stil stabbing in the dark a bit, if anyone can
give me any advice as to what i may or may not be doing that is causing the
problems thanks.

Nice.


This message was sent using IMP, the Internet Messaging Program.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at the Yahoo! Mail Championships. Plus: play games and win prizes.
http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk

Hello !

as this is the only mailing list i subscribe to i’m posting this here,

i have some code for a game i am working on where there is a keys.c that
contains the functions for checking for key events, keys.h contains
integer definitions to hold key presses, when i compile, the compiler i am
using on windows ( devc++ (mingw) ) spits back at me i have multiple
definitons, in main.c i need to #include keys.h for quit and mouse stuff,
so it says i have multiple defintions in keys.c and main.c yet i have
another program that does not do this, also when i try using riscos gcc
with exactly the same source code it gives me no warnings or errors, help!

i have another game i am working on that is pretty much the same setup,
but it dosnt complain!

i used to be a single file code writer, but recently i’ve been trying to
make my code properly modular, so i am stil stabbing in the dark a bit, if
anyone can give me any advice as to what i may or may not be doing that is
causing the problems thanks.

I hope this is the thing you want to know.

You need to put something like :

#ifndef _FILENAME
#define _FILENAME

#endif

around your include file.

The first time your include will be included _FILENAME
is not defined and the include will be integrated,
the next times you include the file _FILENAME is defined
and will not be included again.

CU