none
Error LNK2005 RRS feed

  • Question

  • Good day, I am trying to make game in DirectX.

    I have 6 files: CApplication.cpp , CApplication.h , CWindow.h , CWindow.cpp , Global.h and WinMain.cpp

    Part of Global.h:

    #define _CRT_SECURE_NO_DEPRECATE 1;
    #pragma once
    
    #include<Windows.h>
    #include<stdio.h>
    #include<d3d9.h>
    
    #pragma comment(lib,"dxguid.lib")
    #pragma comment(lib,"d3d9.lib")
    
    #define APP_NAME TEXT("VesmírCraft")
    #define SCREEN_WIDTH 640
    #define SCREEN_HEIGHT 480
    #define SCREEN_DEPTH 32
    #define NUMBER_OF_VERTICES 6
    #define D3DFVF_CUSTOMVERTEX ( D3DFVF_XYZRHW | D3DFVF_DIFFUSE );
    
    #define WAITING_FOR_FLIP 10
    #define FRONTTEXT		TEXT(" Front Buffer ")
    #define BACKTEXT		TEXT(" Back Buffer ")
    
    #define RELEASE_DX_OBJECT(p) {if(p){ (p)->Release(); p=NULL;};};
    
    extern CHAR g_tcError[255];
    extern UINT actapp=TRUE;
    

    Part of WinMain.cpp:

    #include "Global.h"
    #include "CApplication.h"
    
    int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
    {
    	CApplication App;
    	MSG msg;
    	if(!App.Initialize()){
    		MessageBoxA(NULL,"An error has happened",
    			"VesmírCraft",MB_ICONERROR);	
    		return(0);
    	}
    	while(true){
    		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
    			if(msg.message==WM_QUIT)
    				break;
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}		
    		if(actapp)
    			App.MainLoop();
    		//anything here
    	}
    	return(msg.wParam);
    }
    

    Part of CWindow.cpp

    LRESULT CALLBACK WndProc(HWND m_hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam){
    	switch(uMsg){
    	case WM_ACTIVATEAPP:
    		actapp=wParam;
    		return(0);
    	case WM_KEYDOWN:
    		switch(wParam){
    		case VK_ESCAPE:
    			PostQuitMessage(0);
    			break;
    		}
    		break;
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		break;
    	}
    	return DefWindowProc(m_hWnd,uMsg,wParam,lParam);
    }
    And I have this error:

    1>CWindow.obj : error LNK2005: "unsigned int actapp" (?actapp@@3IA) already defined in CApplication.obj

    1>WinMain.obj : error LNK2005: "unsigned int actapp" (?actapp@@3IA) already defined in CApplication.obj

    What is problem?

    "actapp" is nowhere in code of CApplication.cpp and .h 

     




    • Edited by jakubinf Wednesday, January 25, 2012 4:23 PM
    Wednesday, January 25, 2012 4:21 PM

Answers

  • By #including global.h in more than one place you are creating two actapp variables.

    Change the .h file to:

    extern UINT actapp;

    And put this in WinMain.cpp, right after the #includes

    UINT actapp=TRUE;

    • Marked as answer by jakubinf Wednesday, January 25, 2012 5:50 PM
    Wednesday, January 25, 2012 5:36 PM