🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

header files and linker errors

Started by
2 comments, last by xSuiCidEx 24 years, 5 months ago
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===---
Advertisement
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

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
Another thing helps to avoid errors like this, too.
#ifndef MAIN_H_INCLUDED#define MAIN_H_INCLUDED//Your stuff#endif 

This topic is closed to new replies.

Advertisement