473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Multiple Definitions

I keep getting this multiple definition of scr error. It says it's
defined once in main.cc, and first defined in screen.cc
I'm assuming this is because both screen.cc and main.cc include
screen.h, but I figured the #ifndef would take care of that. If
that's not what it's good for, what IS it good for? Anyways, I'm
clearly doing something wrong, what is the proper way of setting this
up?
// main.cc

#include "screen.h"

int main(int argc, char *argv[])
{

SDL_Quit();
return EXIT_SUCCESS;
}

// screen.cc

#include <SDL_image.h>
#include "screen.h"

extern SDL_Surface *scr;

void screen(int width, int height, const char *title, const char
*icon)
{
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);
SDL_WM_SetCaption(title, 0);
SDL_WM_SetIcon(IMG_Load(icon), 0);
scr = SDL_SetVideoMode ( width, height, 32, SDL_HWSURFACE |
SDL_DOUBLEBUF );
}

// screen.h

#ifndef _screen_H
#define _screen_H

#include "SDL.h"

SDL_Surface *scr;

void screen(int width, int height, const char *title="untitled", const
char *icon=NULL);

#endif /* _screen_H */

May 1 '07 #1
3 2088
Mark wrote:
// screen.cc

#include <SDL_image.h>
#include "screen.h"

extern SDL_Surface *scr;
Change to:
SDL_Surface * scr;

#ifndef _screen_H
#define _screen_H

#include "SDL.h"

SDL_Surface *scr;
Change to:
extern SDL_Surface * scr;
May 1 '07 #2
On May 1, 1:25 pm, Noah Roberts <u...@example.netwrote:
Mark wrote:
// screen.cc
#include <SDL_image.h>
#include "screen.h"
extern SDL_Surface *scr;

Change to:
SDL_Surface * scr;
#ifndef _screen_H
#define _screen_H
#include "SDL.h"
SDL_Surface *scr;

Change to:
extern SDL_Surface * scr;
heh...that's simple enough. I just figured it was standard to
actually declare the variables in the .h file, since that's what we do
with classes. But this will do just fine, thank you very much!

May 1 '07 #3
Mark wrote:
On May 1, 1:25 pm, Noah Roberts <u...@example.netwrote:
>Mark wrote:
>>// screen.cc
#include <SDL_image.h>
#include "screen.h"
extern SDL_Surface *scr;
Change to:
SDL_Surface * scr;
>>#ifndef _screen_H
#define _screen_H
#include "SDL.h"
SDL_Surface *scr;
Change to:
extern SDL_Surface * scr;

heh...that's simple enough. I just figured it was standard to
actually declare the variables in the .h file, since that's what we do
with classes. But this will do just fine, thank you very much!
You do.

extern SDL_Surface * scr;

is a "declaration" of a variable.

SDL_Surface * scr;

is a "definition" of a variable.

As with classes and other things, you can declare many times...you can
only define once. So you only *define* in a .cpp file.
May 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: prettysmurfed | last post by:
Hi all I have this, probably stupid question, how to avoid multiple definitions when a header file is included more than once. I thought, when you wrote the header-file and used the...
2
by: Martin Magnusson | last post by:
I have a problem with multiple definitions that I can't quite straighten out. I have a templated class defined inside a namespace, and I want to create a function in that namespace that works on...
5
by: Charles L | last post by:
Can someone explain to me what the following means? "C permits multiple definitions of a variable in any given namespace, provided the definitions are the same and it generates only a single...
2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
4
by: JackyMove | last post by:
Dear all, I have encount the following problem. I have compiled a library "lib.lib" successfully using a simulator compatable to VC++ on Windows platform. Then I try to build an executatble in...
14
by: Carramba | last post by:
hi! I have program with several funktion witch are in separete files, I have one include file were I have definet some variables and initiated 'const double fVar=0.874532;' this files is includet...
9
by: lbj137 | last post by:
I have two files: A.c and B.c. In both files I define a global variable, int xxxx; When I compile with a green hills compiler (and also i think with a GNU compiler) I get no errors or warnings....
8
by: yossi.kreinin | last post by:
Hi! When are multiple definitions of global variables with the same name considered legal in C, and how is it different from C++? It appears that in terms of assembly language, some C...
6
by: javan | last post by:
Hello, I am new to C++, coming from a background in Java and procedural languages. I am currently translating some code from Java to C++ as an exercise and have run into the following problem: ...
4
by: junyang | last post by:
Hi all, I have one DTD fragment, base.dtd, that contains a bunch of useful element definitions (say an element named "base"), and two DTD fragments, a.dtd and b.dtd, that each build on base.dtd...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.