header files and linker errors
im using ms vc++ 5.0
my project uses the following files:
Main.cpp
Main.h
DirectDraw.cpp
DirectInput.cpp
DirectSound.cpp
i have all the functions that are in directdraw.cpp, directinput.cpp, directsound.cpp, and main.cpp defined in main.h
i also got a bunch of things defined in main.h such as:
bool Rebuilding = false;
long FPS = 0;
now when i build my project everything compiles alright, but i get hundreds of linker errors saying stuff like this:
DirectInput.obj : error LNK2005: "struct IDirectDrawSurface7 * DDSWalls" (?DDSWalls@@3PAUIDirectDrawSurface7@@A) already defined in DirectDraw.obj
DirectInput.obj : error LNK2005: "bool FullScreen" (?FullScreen@@3_NA) already defined in DirectDraw.obj
etc.
i think its trying to define all the stuff in main.h more than once, i added:
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
isn''t that suppose to make sure it only compiles once per build?
thanx
brad
---===xxxx===---
----THE END----
---===xxxx===---
----THE END----
---===xxxx===---
quote:
i think its trying to define all the stuff in main.h more than once, i added:
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
isn''t that suppose to make sure it only compiles once per build?
Correct. If you have MSVC or #define _MSC_VER >= 1000 and your compiler supports pragma options, it will compile only once. You didn''t say if it fixed your problem, although your on the right track if it didn''t.
~deadlinegrunt
January 12, 2000 11:56 PM
your defining variables inside your header file, and in effect.. your defining multiple copies of your variables...
thats why the compiler complains..
define the variable in its source file... and declare it in the header file as extern...
example:
i see you have a directdraw surface that you are defining in your header...
define it in your directdraw source file..
and add:
extern LPDIRECTDRAWSURFACE "surfacename" (or whatever it is you inteded)
to your header file
hope it helps
thats why the compiler complains..
define the variable in its source file... and declare it in the header file as extern...
example:
i see you have a directdraw surface that you are defining in your header...
define it in your directdraw source file..
and add:
extern LPDIRECTDRAWSURFACE "surfacename" (or whatever it is you inteded)
to your header file
hope it helps
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement