• Advertisement

Archived

This topic is now archived and is closed to further replies.

LNK1169: one or more multiply defined symbols found

This topic is 5755 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m programming a simple DirectDraw game, and the compiler says:
Main.obj : error LNK2005: _IID_IDirectDrawSurface already defined in Graphics.obj 
Note that it says that for a lot of stuff (all DirectDraw interfaces), 16 to be exact! Followed by the error (the thread title). I have absolutely no idea what might be causing this, but if it said ''multiple defined symbols found'', that might have something to do with my extern stuff. I''ll show you:
  
// Graphics.h

extern LPDIRECTDRAW  lpdd;    // Pointer to the DirectDraw interface

extern LPDIRECTDRAW7 lpdd7;   // Pointer to the DirectDraw 7 interface


// Main.h

extern LPDIRECTDRAW  lpdd;    // Pointer to the DirectDraw interface

extern LPDIRECTDRAW7 lpdd7;   // Pointer to the DirectDraw 7 interface


// Graphics.cpp

LPDIRECTDRAW  lpdd = NULL;	// Pointer to the DirectDraw interface

LPDIRECTDRAW7 lpdd7 = NULL;     // Pointer to the DirectDraw 7 interface

  
You''ll notice that I just called extern on all of them except the C++ file. I''m doing what that new tutorial on including files or something said, defining extern variables elsewhere, and initializing the real variables in a C++ file (that''s not being included by anything). if (input) { tuxx->Appreciate(&you->input); }

Share this post


Link to post
Share on other sites
Advertisement
are you using inclusion guards? if not, try putting:

#ifndef _THIS_FILE_H_
#define _THIS_FILE_H_
// code here
#endif

you would replace THIS_FILE with the name of the file, and H with the type of file(e.g. HPP, H, C, CPP)

Share this post


Link to post
Share on other sites
Hmm, thanks for the reply, but it still doesn''t work . I''ve added the #ifndef stuff to all of my files, including CPPs. But it still didn''t work! I took the #ifndefs out of the CPPs, but I''ll just give you a little code dump in case I''m missing some really easy-to-solve problem.

  
// Main.h

#ifndef _MAIN_H_
#define _MAIN_H_

// Optimize Windows

#define WIN32_LEAN_AND_MEAN
#define INITGUID

// #includes

#include <windows.h> // Windows header file
#include <ddraw.h> // DirectDraw header file


// libs

#pragma comment (lib,"DDRAW.LIB") // Link the DirectDraw library

#pragma comment (lib,"DXGUID.LIB") // Link the DirectX GUID library

#pragma comment (lib,"WINMM.LIB") // Link the Windows Media library


// #defines

// Basic key input

#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
// MessageBox()

#define MSGBox(text,cap) (MessageBox(NULL,text,cap,MB_OK))
#define ErrorMSG(text) (MessageBox(NULL,text,"Error"MB_OK | MB_ICONEXCLAMATION ))

// Globals

extern HWND hwnd; // Handle to window

extern HDC hdc; // Handle to device context

extern WNDCLASSEX wc; // Window class

extern PAINTSTRUCT ps; // Handle to painting structure

extern MSG msg; // Handle messages


// DirectDraw globals

extern LPDIRECTDRAW lpdd; // Pointer to the DirectDraw interface

extern LPDIRECTDRAW7 lpdd7; // Pointer to the DirectDraw 7 interface


// Function declarations

int WINAPI WinMain(HINSTANCE hInstance, // main()

HINSTANCE hPrecInstance,
LPSTR lpCmdLine,
int nShowCmd);

LRESULT CALLBACK WindowProc(HWND hwnd, // Window procedure

UINT msg,
WPARAM wparam,
LPARAM lparam);

int Init(); // Initializer function

int Main(); // Main function

int Shutdown(); // Shutdown function


#endif

// Graphics.h

#ifndef _GRAPHICS_H_
#define _GRAPHICS_H_

// Includes

#include "Main.h"

// Globals


// DirectDraw globals

extern LPDIRECTDRAW lpdd; // Pointer to the DirectDraw interface

extern LPDIRECTDRAW7 lpdd7; // Pointer to the DirectDraw 7 interface


// Function definitions

extern int GInit(); // Graphics initialization

extern int GMain(); // Graphics main loop

extern int GShutdown(); // Graphics shutdown


#endif


  
// And now for Main.cpp and Graphics.cpp

// Main.cpp

// Includes

#include "Main.h"

// Globals

HWND hwnd; // Handle to window

HDC hdc; // Handle to device context

WNDCLASSEX wc; // Window class

PAINTSTRUCT ps; // Handle to painting structure

MSG msg; // Handle messages


int Init(); // Initialization

int Main(); // Main loop

int Shutdown(); // Program shutdown


// Function definitions

//////////////////////////////////////////////////////////////////////

int Init()
{
return 0;
}

//////////////////////////////////////////////////////////////////////

int Main()
{
if(KEYDOWN(VK_ESCAPE)) { Shutdown(); PostQuitMessage(0); }

return 0;
}

//////////////////////////////////////////////////////////////////////

int Shutdown()
{
return 0;
}

//////////////////////////////////////////////////////////////////////

LRESULT CALLBACK WindowProc(HWND hwnd, // Window Procedure function

UINT msg,
WPARAM wparam,
LPARAM lparam)
{
// handle messages

switch(msg)
{
case WM_CREATE: // initialization

{
return (0);
} break;

case WM_PAINT: // painting

{
// validate window

hdc = BeginPaint(hwnd,&ps);

EndPaint(hwnd,&ps);
return (0);
} break;

case WM_DESTROY: // closing

{
// kill program

PostQuitMessage(0);

return (0);
} break;

default:break;
}
return (DefWindowProc(hwnd,msg,wparam,lparam));
}

//////////////////////////////////////////////////////////////////////

int WINAPI WinMain(HINSTANCE hInstance, // WinMain()

HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{


wc.cbSize = sizeof(WNDCLASSEX); // set the size of window class

wc.style = CS_VREDRAW | CS_HREDRAW
| CS_OWNDC | CS_DBLCLKS; // set the window style

wc.lpfnWndProc = WindowProc; // specify function

wc.cbClsExtra = 0; // extra class variable

wc.cbWndExtra = 0; // extra window variable

wc.hInstance = hInstance; // specify instance

wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); // specify icon

wc.hCursor = LoadCursor(NULL,IDC_ARROW); // specify cursor

wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // white background

wc.lpszMenuName = NULL; // no menu

wc.lpszClassName = "WinClass"; // name of class

wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION); // small icon


RegisterClassEx(&wc);

// create window

if (!(hwnd = CreateWindowEx(NULL, // no extended params

"WinClass", // class name

"Framework", // window name

WS_OVERLAPPEDWINDOW | WS_VISIBLE, // popup window

0,0, // start window at top left

640,480, // specify window''s resolution

NULL, // handle to parent

NULL, // handle to menu

hInstance, // handle to instance

NULL))) // advanced window creation data

{ return 0; }

UpdateWindow(hwnd); // force Windows to create WM_PAINT message


Init(); // initialize program


while(GetMessage(&msg,NULL,0,0)) // catch messages

{
// translate accelerator keys

TranslateMessage(&msg);

Main(); // main loop


// send message to WindowProc()

DispatchMessage(&msg);
}

Shutdown(); // shutdown program


return (msg.wParam);
}

// Now for Graphics.cpp (don''t worry, this is shorter)

// Includes

#include "Graphics.h"

// Globals


// DirectDraw globals

LPDIRECTDRAW lpdd = NULL; // Pointer to the DirectDraw interface

LPDIRECTDRAW7 lpdd7 = NULL; // Pointer to the DirectDraw 7 interface


// Function definitions

int GInit(); // Graphics initialization

int GMain(); // Graphics main loop

int GShutdown(); // Graphics shutdown


// Function declarations

////////////////////////////////////////////////

int GInit()
{
// Create the DirectDraw interface

DirectDrawCreate( NULL, &lpdd, NULL );

// Upgrade to DirectDraw 7

lpdd->QueryInterface( IID_IDirectDraw7, (LPVOID*)lpdd7 );

return 0;
}

////////////////////////////////////////////////

int GMain()
{
return 0;
}

////////////////////////////////////////////////

int GShutdown()
{
return 0;
}

Whew. If any of you could see what I''m doing wrong, please reply .

Share this post


Link to post
Share on other sites
Since you have

extern LPDIRECTDRAW lpdd; // Pointer to the DirectDraw interface
extern LPDIRECTDRAW7 lpdd7; // Pointer to the DirectDraw 7 interface

in Graphics.h, you don't need (and shouldn't have) them in Main.h. Try removing them from Main.h and see if that works.

Mike

EDIT: I'm new with the board, so I had to play with the formatting. =)

[edited by - mmelson on April 19, 2002 6:51:07 PM]

Share this post


Link to post
Share on other sites
I'm guessing you've defined INITGUID somewhere, right? Remove all those and include dxguid.lib in your project instead. It's easier and less error-prone.

Edit: I just had a look at your last post, where do you include the directx headers? Let's have a look at that.

PS, you can declare things extern as many times as you like and it makes no difference (unless you change the calling convention or return code or something like that).


codeka.com - Just click it.

[edited by - Dean Harding on April 19, 2002 10:25:56 PM]

Share this post


Link to post
Share on other sites
shit, thanks Dean! It works! Thanks everyone else too. All I had to do is remove INITGUID! Thanks!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Jon starts working in a lumber camp. The boss says, "We work twelve hours a day, we eat two meals a day, lights out at ten-thirty, and you can put your dick in the barrel over there for a blow job any day but Thursday." Jon says, "Why not Thursday?" The boss says, "Because Thursday is your turn in the barrel."

Share this post


Link to post
Share on other sites

  • Advertisement