HDC hDC=NULL;
HGLRC hRC=NULL;
HWND hWnd=NULL;
HINSTANCE hInstance;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow);
GLvoid ReSizeGLScene(GLsizei width, GLsizei height);
int InitGL(GLvoid);
int DrawGLScene(GLvoid);
GLvoid KillGLWindow(GLvoid);
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag);
and the fullscreen and active flags
Now, all the compilation is fine, but when it comes to linking :
Compiling...
WinMain.cpp
InitGL.cpp
callback.cpp
Linking...
InitGL.obj : error LNK2005: "bool fullscreen" (?fullscreen@@3_NA) already defined in WinMain.obj
InitGL.obj : error LNK2005: "bool active" (?active@@3_NA) already defined in WinMain.obj
InitGL.obj : error LNK2005: "struct HWND__ * hWnd" (?hWnd@@3PAUHWND__@@A) already defined in WinMain.obj
InitGL.obj : error LNK2005: "struct HGLRC__ * hRC" (?hRC@@3PAUHGLRC__@@A) already defined in WinMain.obj
InitGL.obj : error LNK2005: "struct HDC__ * hDC" (?hDC@@3PAUHDC__@@A) already defined in WinMain.obj
InitGL.obj : error LNK2005: "char * g_WindowTitle" (?g_WindowTitle@@3PADA) already defined in WinMain.obj
InitGL.obj : error LNK2005: "struct HINSTANCE__ * hInstance" (?hInstance@@3PAUHINSTANCE__@@A) already defined in WinMain.obj
InitGL.obj : error LNK2005: "bool * keys" (?keys@@3PA_NA) already defined in WinMain.obj
callback.obj : error LNK2005: "bool fullscreen" (?fullscreen@@3_NA) already defined in WinMain.obj
callback.obj : error LNK2005: "bool active" (?active@@3_NA) already defined in WinMain.obj
callback.obj : error LNK2005: "struct HWND__ * hWnd" (?hWnd@@3PAUHWND__@@A) already defined in WinMain.obj
callback.obj : error LNK2005: "struct HGLRC__ * hRC" (?hRC@@3PAUHGLRC__@@A) already defined in WinMain.obj
callback.obj : error LNK2005: "struct HDC__ * hDC" (?hDC@@3PAUHDC__@@A) already defined in WinMain.obj
callback.obj : error LNK2005: "char * g_WindowTitle" (?g_WindowTitle@@3PADA) already defined in WinMain.obj
callback.obj : error LNK2005: "struct HINSTANCE__ * hInstance" (?hInstance@@3PAUHINSTANCE__@@A) already defined in WinMain.obj
callback.obj : error LNK2005: "bool * keys" (?keys@@3PA_NA) already defined in WinMain.obj
Debug/RT.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
RT.exe - 17 error(s), 0 warning(s)
Well, what's the problem ?, how do I correct it ?
Knowing stuff like main.h, contains globals that will be used in all the files ...
Yeah, and, how do you make these good looking Visual-Studio-like stuff to type the code in because that looks much more neat than that code stuff (you see what I mean, don't you ?)
Edited by - SKSlayer on 8/16/00 6:09:46 AM
Problem with multiple cpp
I made a little test
I took nehe's solid object code
then make 3 .cpp and 3 .h
callback.cpp // Contains the callback procedure, includes globals.h and main.h
InitGL.cpp // Contains everything but the WinMain and CallBack funcs, includes globals.h main.h and errors.h
WinMain.cpp // Contains the WinMain function, includes globals.h and main.h
all header have something like this (of course, it changes with the name of the file)
#ifndef ERROR_H
#define ERROR_H
Header code
#endif
errors.h contains stuff such as
char sderr_err000[]="Release Of DC And RC Failed.";
which are called in the error messagebox
globals.h
have 4 includes, for the GL system(gl/gl.h gl/glu.h gl/glaux.h) and windows.h
+ a global with the window title
and that bool keys[256];
main.h
Contains all the function predefinitions like
(you can find me on IRC : #opengl on undernet)
Try throwing:
(This at the top of each header, ''filename'' must be unique in each header)
#ifndef filename
#define filename
(Add this at the bottom)
#endif
(This at the top of each header, ''filename'' must be unique in each header)
#ifndef filename
#define filename
(Add this at the bottom)
#endif
You defined the variables. You can only declare them.
Copy all your variables definitions in a .cpp file. Add the "extern" keyword before all your variables in headers, and remove the default value assignment.
Read my new reply to your other multiple files thread for the explanation of the problem (i.e.: linker VS compiler).
This is how your declarations should look like:
extern char sderr_err000[];
extern bool keys[256];
while in one of your .cpp file, you should have your previous
char sderr_err000[]="Release Of DC And RC Failed.";
bool keys[256];
Try to understand declaration VS definition, it will help. A declaration is a statement that a variable exists, somewhere, while the definition is the act of creating the variable and to give it a value.
EL
----------------------------------------
"Inash neteia haeg joa kavari quilm..." SD4
Copy all your variables definitions in a .cpp file. Add the "extern" keyword before all your variables in headers, and remove the default value assignment.
Read my new reply to your other multiple files thread for the explanation of the problem (i.e.: linker VS compiler).
This is how your declarations should look like:
extern char sderr_err000[];
extern bool keys[256];
while in one of your .cpp file, you should have your previous
char sderr_err000[]="Release Of DC And RC Failed.";
bool keys[256];
Try to understand declaration VS definition, it will help. A declaration is a statement that a variable exists, somewhere, while the definition is the act of creating the variable and to give it a value.
EL
----------------------------------------
"Inash neteia haeg joa kavari quilm..." SD4
----------------------------------------"Inash neteia haeg joa kavari quilm..." SD4
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement