|
-
Mar 17th, 2002, 05:06 PM
#1
Thread Starter
Addicted Member
Link error !?!?!?!?!
Ok, another stupid problem! I compile my program... so far so good. Then it gets to the linking part and it gives me a mother-load of errors, pretty much an error for every function i have defined in my header file:
error: 'int Render() [some other stuff]' already defined in MyHeader.obj
What does this mean and how do i fix it?????
To protect time is to protect everything...
-
Mar 17th, 2002, 07:45 PM
#2
Monday Morning Lunatic
You don't put the actual code into the header, just the prototype. The code needs to go into a separate .cpp file, otherwise you will, obviously, get these linker errors because as far as the linker is concerned, the same function code exists in every .cpp file that includes your header.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 17th, 2002, 11:34 PM
#3
Thread Starter
Addicted Member
I know.... I have only proto types in my .h file and the actual code is in a .cpp file. I have multiple .cpp files using the same .h file. Might that cause this problem?
To protect time is to protect everything...
-
Mar 18th, 2002, 04:24 AM
#4
Monday Morning Lunatic
No, it shouldn't make any difference.
Do you have the same function defined in the .cpp files then? The linker's basically telling you it's collected all the object files together, and it's found more than one function (code) with the same prototype.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 18th, 2002, 05:55 AM
#5
Fanatic Member
There's a way to include any declarations, prototypes, constants, etc only once. Only the first time the header is included, its contents are expanded in the compiler.
Code:
#ifndef MYFILE_H
#define MYFILE_H
(put all stuff from your header file here)
#endif
In some cases (I think it's with DLL's) it is absolutely necessary to include your header file only once.
-
Mar 18th, 2002, 08:21 AM
#6
Thread Starter
Addicted Member
Well I just dont know whats wrong then...
I have:
#ifndef MY_HEADER
#define MY_HEADER
..... header code
#endif
The compiler (which is VC++ 6.0 by the way) is telling me that I have many many different functions and variables "already defined in MyHeader.obj". I know i don't have all of them defined in more than one .cpp file. In fact I'm almost positive that I don't have any. ??????????????
To protect time is to protect everything...
-
Mar 18th, 2002, 08:24 AM
#7
Monday Morning Lunatic
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 18th, 2002, 09:13 AM
#8
Thread Starter
Addicted Member
Same result.....
I Have 1 .h file and 3 .cpp files. All of the .cpp files include the .h file.
one_cpp.obj error: LNK2005 "bool SomeBool" (C++ Mangled name) already defined in first_cpp.obj
one_cpp.obj error: LNK2005 "int SomeFunc" (C++ mangled...) already defined in first_cpp.obj
.............???? there are 10 errors all like this.... i've never had this problem b4.... I don't get it ?????
To protect time is to protect everything...
-
Mar 18th, 2002, 09:14 AM
#9
Monday Morning Lunatic
Can you post the contents of your .h file?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 18th, 2002, 09:21 AM
#10
Thread Starter
Addicted Member
Ok, here goes.........
Code:
#ifndef MY_HEADER
#define MY_HEADER
#pragma once
// Includes...
#include <windows.h>
#include <d3dx8.h>
// Macros...
#define R_OK = 100
#define R_ERROR = 101
#define R_STOP_RENDER = 102
#define DLL_OK = 800
#define DLL_ERROR = 801
// Globals...
typedef INT (*DLLFUNC_VOID)(void);
typedef INT (*DLLFUNC_RETVAL)(DXAPP_SYSTEM *dll_dx);
typedef INT (*DLLFUNC_STRRET)(const char *str, long sTyp);
HINSTANCE hDLL;
DLLFUNC_STRRET DLL_SRETURN;
DLLFUNC_RETVAL DLL_CREATE;
DLLFUNC_RETVAL DLL_SET_DXAPPSYS;
DLLFUNC_VOID DLL_UPDATE;
DLLFUNC_VOID DLL_RELEASE;
HWND APPhWnd;
bool HALRender = false;
bool SceneInit = false;
// Prototypes...
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
HRESULT InitD3D( HWND hWnd );
INT InitScene( const char *dll );
INT UpdateScene( const char * dll );
INT EndScene( const char *dll );
INT Render();
void CleanUp();
void ErrorMsg( const char *msg, const char *caption, bool fatal );
void Quit();
void OneTimeRender();
// End MY_HEADER
#endif
I've tired taking the #pragma once in and out and it results in no change.......
To protect time is to protect everything...
-
Mar 18th, 2002, 09:31 AM
#11
Monday Morning Lunatic
Do all three .cpp files provide code for those functions, or is there only ever one set of source, in one file?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 18th, 2002, 09:37 AM
#12
Thread Starter
Addicted Member
Each .cpp file provides code for their share of functions. I have one .cpp file handling all the windows stuff, and another handling the direct 3d stuff. The third has all been commented out right now b/c it has bugs.
To protect time is to protect everything...
-
Mar 18th, 2002, 09:40 AM
#13
Monday Morning Lunatic
In that case, I have absolutely no idea.
The only reason the linker should complain is if more than one .cpp file contains code for the same function, which you've said isn't the case.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 18th, 2002, 09:44 AM
#14
Thread Starter
Addicted Member
Well i can like quadruple check but im pretty sure...... thanx anyway tho...
To protect time is to protect everything...
-
Mar 18th, 2002, 04:29 PM
#15
I'd understand if the linker complained about the variables...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 18th, 2002, 04:36 PM
#16
Hyperactive Member
this is going to sound stupid, but i think it worked for me once.
erase the debug folder, and copy the whole project somewhere else on your hd, then recompile..i dont know why this would work, but it did once for me
Amon Ra
The Power of Learning.
-
Mar 18th, 2002, 05:47 PM
#17
Thread Starter
Addicted Member
Well if i put the option FORCE:MULTIPLE in the linker options it sets all those errors as warnings.... so yeah i guess that works... the program seems to run fine... but i dont know if i'll run into something along the way.
To protect time is to protect everything...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|