Advertisement

AHHh!! help with multiple cpp files...

Started by August 20, 2000 05:27 AM
5 comments, last by Quantum 24 years, 4 months ago
i know this has been mentioned before.. but i just CANNOT get this damn thing to work i am working on a game using directx, and i had main.h and main.cpp before.. it all works fine, but i decide i wanna split up my code a bit more so i make a bitmap.h and a bitmap.cpp main.cpp includes main.h and bitmap.h, giving it access to the functions forloading bitmaps bitmap.cpp includes main.h and bitmap.h, because theres stuff in main.h that it needs, and it ofcourse needs the function protocols etc from bitmap.h i put #ifndef _bla_h_ etc.. in my header files, and it all compiles fine, but i get a lot of errors in the linking stage bitmap.obj : error LNK2005: "struct IDirectDrawSurface * lpddsbg" (?lpddsbg@@3PAUIDirectDrawSurface@@A) already defined in main.obj bitmap.obj : error LNK2005: "struct IDirectDrawSurface * lpddsback" (?lpddsback@@3PAUIDirectDrawSurface@@A) already defined in main.obj ...etc (im not supposed to include the bitmap.cpp file am i?) so, anyone?
I''m not sure how to fix this, but you could try using externals.

Declare lpddsbg like this, in bitmap.h:
extern LPDIRECTDRAWSURFACE lpddsbg;

And in Main.h:
LPDIRECTDRAWSURFACE lpddsbg;

That way you tell Bitmap.h that this surface is in one of the external files (Main.h).
Try it, it should work



The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction
Advertisement
Well if you''re using Borland command line tools you have to compile them like this:

BCC32 -tW main.cpp bitmap.cpp ddraw.lib etc

In VC++ I don''t know the exact syntax because I''ve never used it. Just link them together.

http://users.50megs.com/crazyvasey/
i tried what tornado said, and i still got the same errors!!

someone must be able to help... PLEASE
Try remake/recompile all modules. Sometimes things get stuck somehow. What Tornado said should work: if bitmap.cpp sees "extern" it should know it exists somewhere else...

Edited by - X-Man on August 20, 2000 8:16:16 AM
Also, make sure you aren''t defining lpddsback and lpddsbg in both files. They should only be declared in one file. For instance:

    //main.cppLPDIRECTDRAWSURFACE lpddsback;LPDIRECTDRAWSURFACE lpddsbg;//main.h#pragma once //(same effect as the #ifndef thing)extern LPDIRECTDRAWSURFACE lpddsback;extern LPDIRECTDRAWSURFACE lpddsbg;//bitmap.cpp#include "main.h"//do stuff here    


----------------------------------------
"Before criticizing someone, walk a mile in their shoes.
Then, when you do criticize them, you will be a mile away and have their shoes." -- Deep Thoughts

"If you have any trouble sounding condescending, find a Unix user to show you how it's done." - Scott Adams
Advertisement
thankyou senshi, it worked great

This topic is closed to new replies.

Advertisement