Sign in to follow this  
CarloSpain

Linker Errors in VC++

Recommended Posts

CarloSpain    122
Hello, im building my game in object oriented model. But I get theese linker errores while building (I already include ddraw.lib)
1>Mapa.obj : error LNK2005: ya se definió "struct IDirectDrawSurface7 * lpddsPrimary" (?lpddsPrimary@@3PAUIDirectDrawSurface7@@A) en CDirectD.obj
1>Mapa.obj : error LNK2005: ya se definió "struct IDirectDraw7 * lpdd7" (?lpdd7@@3PAUIDirectDraw7@@A) en CDirectD.obj
1>Mapa.obj : error LNK2005: ya se definió "struct IDirectDrawClipper * lpddClipper" (?lpddClipper@@3PAUIDirectDrawClipper@@A) en CDirectD.obj
1>Mapa.obj : error LNK2005: ya se definió "struct IDirectDrawSurface7 * lpddsTileset" (?lpddsTileset@@3PAUIDirectDrawSurface7@@A) en CDirectD.obj
1>Mapa.obj : error LNK2005: ya se definió "struct HINSTANCE__ * hMainInstance" (?hMainInstance@@3PAUHINSTANCE__@@A) en CDirectD.obj
1>Mapa.obj : error LNK2005: ya se definió "struct _DDSURFACEDESC2 ddsd" (?ddsd@@3U_DDSURFACEDESC2@@A) en CDirectD.obj
1>Mapa.obj : error LNK2005: ya se definió "struct HWND__ * hMainWindow" (?hMainWindow@@3PAUHWND__@@A) en CDirectD.obj
1>Mapa.obj : error LNK2005: ya se definió "struct IDirectDrawSurface7 * lpddsBack" (?lpddsBack@@3PAUIDirectDrawSurface7@@A) en CDirectD.obj
1>main.obj : error LNK2005: ya se definió "struct IDirectDrawSurface7 * lpddsPrimary" (?lpddsPrimary@@3PAUIDirectDrawSurface7@@A) en CDirectD.obj
1>main.obj : error LNK2005: ya se definió "struct IDirectDraw7 * lpdd7" (?lpdd7@@3PAUIDirectDraw7@@A) en CDirectD.obj
1>main.obj : error LNK2005: ya se definió "struct IDirectDrawClipper * lpddClipper" (?lpddClipper@@3PAUIDirectDrawClipper@@A) en CDirectD.obj
1>main.obj : error LNK2005: ya se definió "struct IDirectDrawSurface7 * lpddsTileset" (?lpddsTileset@@3PAUIDirectDrawSurface7@@A) en CDirectD.obj
1>main.obj : error LNK2005: ya se definió "struct HINSTANCE__ * hMainInstance" (?hMainInstance@@3PAUHINSTANCE__@@A) en CDirectD.obj
1>main.obj : error LNK2005: ya se definió "struct _DDSURFACEDESC2 ddsd" (?ddsd@@3U_DDSURFACEDESC2@@A) en CDirectD.obj
1>main.obj : error LNK2005: ya se definió "struct HWND__ * hMainWindow" (?hMainWindow@@3PAUHWND__@@A) en CDirectD.obj
1>main.obj : error LNK2005: ya se definió "struct IDirectDrawSurface7 * lpddsBack" (?lpddsBack@@3PAUIDirectDrawSurface7@@A) en CDirectD.obj
1>CDirectD.obj : error LNK2001: símbolo externo _IID_IDirectDraw7 sin resolver
1>C:\Documents and Settings\Administrador\Mis documentos\Visual Studio 2005\Projects\EthernalWar\Debug\EthernalWar.exe : fatal error LNK1120: 1 externos sin resolver
1>El registro de generación se guardó en el "file://c:\Documents and Settings\Administrador\Mis documentos\Visual Studio 2005\Projects\EthernalWar\EthernalWar\Debug\BuildLog.htm"
1>EthernalWar - 18 errores, 0 advertencias
========== Generar: 0 correctos, 1 incorrectos, 0 actualizados, 0 omitidos ==========

Theese errors are in spain, so, I will try to traduce some errores... Ya se definió = Already defined Simbolo externo .... sin resolver = Extern simbol without resolve (¿?, this not sure...) Well I think its because of my includes... I have 3 .cpp, and 3 .h I will just post the includes part main.cpp
#ifndef INCLUDES
#define INCLUDES
#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>
#include <stdio.h>
#include "resource.h"
#endif

#include "Mapa.h"
#include "CDirectD.h"

CdirectD.h
#ifndef INCLUDES
#define INCLUDES
#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>
#include <stdio.h>
#include "resource.h"
#endif

#define TILESET_WIDTH    120
#define TILESET_HEIGHT   360

#define INIT_DXSTRUCT(dxstruct) { ZeroMemory(&dxstruct, sizeof(dxstruct)); dxstruct.dwSize = sizeof(dxstruct); }
#define KEYSTATE(key) ((GetAsyncKeyState(key) & 0x8000) ? TRUE : FALSE)

Mapa.h
#ifndef INCLUDES
#define INCLUDES
#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>
#include <stdio.h>
#include "resource.h"
#endif

#define WORLD_SIZEX		 30
#define WORLD_SIZEY		 30
#define MSCREEN			 640
#define THEIGHT			 80
#define MITADP			 22
#define NUM_TILES                3

resource.h
#define IDB_BITMAP1                     101

HWND hMainWindow;
HINSTANCE hMainInstance;

LPDIRECTDRAW7 lpdd7;
LPDIRECTDRAWSURFACE7 lpddsPrimary;
LPDIRECTDRAWSURFACE7 lpddsBack;
LPDIRECTDRAWSURFACE7 lpddsTileset;
LPDIRECTDRAWCLIPPER  lpddClipper;
DDSURFACEDESC2 ddsd;

Mapa.cpp, and CDirectD.cpp, just contains the functions and the include to their .h files. Hopes that can help me, I have this errors, like... 2 or 3 days ago. Bye! Sorry me english!

Share this post


Link to post
Share on other sites
Evil Steve    2017
The unresolved external error is because you need to liunk to dxguid.lib as well, or define INITGUID (Or INIT_GUID, I can't remember offhand) in one source file (Linking to the lib is easiest).

The other errors look like you've got globals in a header file.

Share this post


Link to post
Share on other sites
CarloSpain    122
I resolve the last error, thanks you :)

But, respect to the other errores...
I have this in resource.h

HWND hMainWindow;
HINSTANCE hMainInstance;

LPDIRECTDRAW7 lpdd7;
LPDIRECTDRAWSURFACE7 lpddsPrimary;
LPDIRECTDRAWSURFACE7 lpddsBack;
LPDIRECTDRAWSURFACE7 lpddsTileset;
LPDIRECTDRAWCLIPPER lpddClipper;
DDSURFACEDESC2 ddsd;




Some functions in CDirectD.cpp, use this surfaces, some functions in Mapa.cpp uses that surfaces too, and main.cpp uses that surfaces too.
Where can I define this variables to edit and use this variables in all my files?
How I can do that?

Thanks,
Carlos

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by CarloSpain
I resolve the last error, thanks you :)

But, respect to the other errores...
I have this in resource.h
*** Source Snippet Removed ***

Some functions in CDirectD.cpp, use this surfaces, some functions in Mapa.cpp uses that surfaces too, and main.cpp uses that surfaces too.
Where can I define this variables to edit and use this variables in all my files?
How I can do that?

Thanks,
Carlos
#include means "Copy the contents of the file to this file, at this location". So you're defining those variables once in each .cpp file that uses them. The correct way to do it is to declare them as extern in the header, and then put the implementation of them in one file.

In the header, it should be:

extern HWND hMainWindow;
extern HINSTANCE hMainInstance;

extern LPDIRECTDRAW7 lpdd7;
extern LPDIRECTDRAWSURFACE7 lpddsPrimary;
extern LPDIRECTDRAWSURFACE7 lpddsBack;
extern LPDIRECTDRAWSURFACE7 lpddsTileset;
extern LPDIRECTDRAWCLIPPER lpddClipper;
extern DDSURFACEDESC2 ddsd;



And in ONE source file (Presumably CDirectD.cpp):

HWND hMainWindow;
HINSTANCE hMainInstance;

LPDIRECTDRAW7 lpdd7;
LPDIRECTDRAWSURFACE7 lpddsPrimary;
LPDIRECTDRAWSURFACE7 lpddsBack;
lpddsTileset;
LPDIRECTDRAWCLIPPER lpddClipper;
DDSURFACEDESC2 ddsd;

The extern keyword simply says "This variable exists, but it's not not implemented here".

However, if this is an object oriented model, those variables should be in a class anyway and not global to the entire application.

Share this post


Link to post
Share on other sites
CarloSpain    122
Thanks you! Now my code works good :)
But I think that its better to use 1 class to surfaces, 1 class to the map, 1 class to the character, etc, like you say.
How can I do to Blt to surfaces in CDirectD?
I tried to write my own function, writing in the arguments the RECT of dest, and RECT of origin. But the compiler says that I cant convert RECT __*w64 to LPRECT :S
What can I do?

Thanks,
Carlos

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by CarloSpain
How can I do to Blt to surfaces in CDirectD?
I tried to write my own function, writing in the arguments the RECT of dest, and RECT of origin. But the compiler says that I cant convert RECT __*w64 to LPRECT :S
What can I do?
What's the exact code you have for that? It sounds like you're trying to cast between a pointer and something that isn't a pointer, or something odd like that (Going by the w64 part).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this