🎉 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!

VC++ problems

Started by
5 comments, last by Jacen 24 years, 5 months ago
Hi, i''ve a big problem with VC++ ...i often get the linker error "Symbol xyz is already defined in *.obj"... i got around this shit by creating a .h file for every .cpp file and including the global .h file in each .h file... ..that means i cannot create one global .h file and include it in every .cpp file.. i always get this linker error... i also tried: #ifndef _NAME_H #define _NAME_H // the .h file #endif it doesn''t work... Can anyone help me? What i am doing wrong? Another problem is: If I create a class with and i allocate mem in constructor and want to free it in destructor the app crashs... if i free the mem myself - everything works fine... What''s that?? PS: the pointer to the mem belongs to the class... Any idea? Thanks...
Advertisement
It sounds like you''ve declared global variables in your header file. If you declare global variables you need to extern them in the header files and then declare them in your source files.

Otherwise I can''t give you much help without seeing the actual error messages.

As for the memory allocation problem, you might want to post the relevant code fragments.
I think SiCrane probably nailed your first problem on the head.

As far as the second one goes, you''ll probably need to post some code here, but you may try stepping through your destructor with the debugger. You might be missing something stupid.
Hi,

the first problem also occurs if i include ddraw.h into my global header file - then the linker says that some DirectX structs are already defined in *.obj while linking...!?

Code (2nd problem)

for example:

//.h file

class __declspec(dllexport) tImage
{
public:
tImage();
~tImage();

unsigned char *buf;
};

// .cpp file

tImage::tImage(void)
{
buf = (unsigned char *)malloc(4096);
}

tImage::~tImage(void)
{
if(buf)
free(buf);
}

...hmmm... what''s wrong?

CU..
You can declare globals in headers without errors using __declspec(selectany)
Example: __declspec(selectany) char szMyString[] = "Hello";
That code (from the second problem) works fine on my compiler (Visual C++ 6.0).
Hi,

__declspec(selectany).. this works? But i want to export this function/class from a dll.. so shouldn''t i use __declspec(dllexport)?

..back to the include problem.. i''ve a global .h file which includes ddraw.h.. this .h file is included in each .cpp file.. when linking i get this error:
"*.obj : error LNK2005: _IID_IDirectDrawSurface3 already defined in *.obj"

...this error and 91 other.. but "already defined things" belong to ddraw.h????

What to do?

CU..

This topic is closed to new replies.

Advertisement