Original Post
Ok I'm trying to organize my project. Because these directx programs tend to get over 1000 lines really quickly, even if your doing something simple.
This is how I arranged my project
I have the C++ files that actually have all the code in them
//This file has both the WinMain function and the WinProc
WinStuff.cpp
GameInitShut.cpp //direct x initilization and shutdown
GameLoop.cpp //has all the render stuff in it
misc.cpp //misc functions like debug
each of those cpp files has a matching header file that declares the function
WinStuff.h
GameInitShut.h
GameLoop.h
misc.h
Also I have an init.h header file that I include on the top of each .cpp file
init.h looks like this
So every .cpp file at the very top has #include "init.h"
but for some reason I'm getting a wierd linking error
--------------------Configuration: Pong - Win32 Debug--------------------
Compiling...
WinStuff.cpp
Linking...
GameLoop.obj : error LNK2005: "struct IDirect3DDevice8 * g_pd3ddev" (?g_pd3ddev@@3PAUIDirect3DDevice8@@A) already defined in GameInitShut.obj
GameLoop.obj : error LNK2005: "struct IDirect3D8 * g_pd3d" (?g_pd3d@@3PAUIDirect3D8@@A) already defined in GameInitShut.obj
misc.obj : error LNK2005: "struct IDirect3DDevice8 * g_pd3ddev" (?g_pd3ddev@@3PAUIDirect3DDevice8@@A) already defined in GameInitShut.obj
misc.obj : error LNK2005: "struct IDirect3D8 * g_pd3d" (?g_pd3d@@3PAUIDirect3D8@@A) already defined in GameInitShut.obj
WinStuff.obj : error LNK2005: "struct IDirect3DDevice8 * g_pd3ddev" (?g_pd3ddev@@3PAUIDirect3DDevice8@@A) already defined in GameInitShut.obj
WinStuff.obj : error LNK2005: "struct IDirect3D8 * g_pd3d" (?g_pd3d@@3PAUIDirect3D8@@A) already defined in GameInitShut.obj
GameInitShut.obj : error LNK2001: unresolved external symbol "enum _D3DDEVTYPE g_devtype" (?g_devtype@@3W4_D3DDEVTYPE@@A)
GameInitShut.obj : error LNK2001: unresolved external symbol "struct HWND__ * g_hWnd" (?g_hWnd@@3PAUHWND__@@A)
WinStuff.obj : error LNK2001: unresolved external symbol "struct HWND__ * g_hWnd" (?g_hWnd@@3PAUHWND__@@A)
Debug/Pong.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Pong.exe - 10 error(s), 0 warning(s)
[/source]
What am I doing wrong? I have never really done too much with includes, and preproccessor directives, because I usually squish everything onto one main.cpp file.
Also are there better ways I should be organizing my project?
[edited by - ph33r on September 29, 2002 4:08:44 PM]
//windows includes #define WIN32_LEAN_AND_MEAN #include <windows.h> //all the direct x includes #include <d3d8.h> #include <d3dx8.h> #ifndef _GLBLL #define _GLBLL IDirect3D8* g_pd3d = 0; IDirect3DDevice8* g_pd3ddev = 0; D3DDEVTYPE g_devtype; HWND g_hWnd; #endif #include "GameInitShut.h" #include "GameLoop.h" #include "WinStuff.h" #include "misc.h"