Skip to main content
gamedev.net
🔒 Locked

extern and SDL_Surface

Started by H0M35T4R Feb 24, 2007 at 2:18 PM 1 replies 650+ views
Original Post
H0M35T4R
H0M35T4R
If i declare a variable using the extern keyword in a header file I am able to define it in another c++ file. However when i use the extern keyword for SDL_Surface,TTF_Font or any other SDL library I cannot define it anywhere else and the linker throws a multiple definition error at me. Example: I have a header file and I declare like this
extern SDL_Surface *Screen 
Then in a separate file c++ source file I define it like this
 SDL_Surface *Screen = NULL; 
If I declare a const or any other datatype it works fine.Is there something else I must do when using abstract datatypes from the SDL Library(if i am correct SDL_Surface can be known as abstract?)
rip-off
rip-off
0) Using extern in a header and defining it once in a source file should work, you are sure you dont make use of another global called "Screen" somewhere?

1) SDL provides a function SDL_GetVideoSurface() which may be niver than your method, it returns the most recent pointer that SDL_SetVideoMode() returned.

H0M35T4R
H0M35T4R
I think I may have found where it is being initialized twice,if I dont set them to NULL it works because they are being used in the main program to load images.

Thanks for the help.I should have realized i am using the surfaces to load images.I just wanted to keep them set to NULL before they are loaded.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.