Code::Blocks Failing To Build

closed account (zb0S216C)
As the title says, Code::blocks is failing at building my project.

Errors

'obj\Release\Include.o:Include.cpp:( .bss+0x0 ) : multiple definition of 'Direct3D''
'obj\Release\main.o:main.cpp:( .bss+0x0 ): first defined here'


There are no errors and no warnings.

What I've Tried

Check if the GNU GCC compiler is installed.
Check for multiple definitions.
Rebuilding the project.

Every-time I try to rebuild the project, Code::Blocks throws a message box at me saying: "It seems that this project has not been built yet. Do you want to build it now?" I click "Yes" and nothing happens.
multiple definition of 'Direct3D''

It says the problem already. Can't really help you without seeing your code.


Try reading this article from Disch.. Good luck!
http://cplusplus.com/forum/articles/10627/
closed account (zb0S216C)
Include.hpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef DIRECT3D_SETUP_HPP
#define DIRECT3D_SETUP_HPP

#include <windows.h>
#include <d3d9.h>

class DIRECT3D
{
    public:

        // Constructor.
        DIRECT3D( void );

        // Destructor.
        ~DIRECT3D( void );

        // Initialize( ). Setups up Direct3D.
        bool Initialize( HWND );

        // Render( ). Renders the current frame.
        void Render( void );

        // Finalize( ). Release any allocated memory.
        void Finalize( void );

        // Interface.
        LPDIRECT3D9 Interface;

        // Device.
        LPDIRECT3DDEVICE9 Device;

        // Parameters.
        D3DPRESENT_PARAMETERS Parameters;
} Direct3D;

#endif 


Include.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "Include.hpp"

// Constructor: DIRECT3D( void )
DIRECT3D::DIRECT3D( void )
{
    // Set both interface and device to NULL.
    Device = NULL;
    Interface = NULL;

    // Initialize the parameters.
    Parameters = D3DPRESENT_PARAMETERS( );

    // Create the interface.
    Interface = Direct3DCreate9( D3D_SDK_VERSION );

}

// Destructor: ~DIRECT3D( void )
DIRECT3D::~DIRECT3D( void )
{
    // Release the memory.
    Finalize( );
}

// Method: Initialize( void )
bool DIRECT3D::Initialize( HWND Window )
{
    // Setup the parameters
    Parameters.Windowed = true;
    Parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
    Parameters.BackBufferFormat = D3DFMT_UNKNOWN;
    Parameters.BackBufferWidth = 500;
    Parameters.BackBufferHeight = 500;
    Parameters.BackBufferCount = 1;
    Parameters.hDeviceWindow = Window;

    if( FAILED( Interface -> CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &Parameters, &Device ) ) )
    {
        return false;
    }
    return true;
}

// Method: Render( void )
void DIRECT3D::Render( void )
{
    // Setup the renderer.
    if( Device == NULL )
    {
        return;
    }

    // Clear the screen to the set colour.
    Device -> Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 63, 63, 63 ), 1.0f, 0 );

    if( SUCCEEDED( Device -> BeginScene( ) ) )
    {
        // Draw...

        // End the scene.
        Device -> EndScene( );
    }

    // Show the back buffer.
    Device -> Present( NULL, NULL, NULL, NULL );
    return;
}

// Method: Finalize( void )
void DIRECT3D::Finalize( void )
{
    // Release the memory.
    if( Device != NULL )
    {
        Device -> Release( );
        Device = NULL;
    }

    if( Interface != NULL )
    {
        Interface -> Release( );
        Interface = NULL;
    }
}


Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "Include.hpp"

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure( HWND, UINT, WPARAM, LPARAM );

/*  Make the class name into a global variable  */
char szClassName[ ] = "CodeBlocksWindowsApp";

int WINAPI WinMain( HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow )
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if( !RegisterClassEx( &wincl ) )
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Code::Blocks Template Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow( hwnd, nCmdShow );

    // Initialize.
    Direct3D.Initialize( hwnd );

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while( messages.message != WM_QUIT || messages.message != WM_DESTROY )
    {
        if( PeekMessage( &messages, NULL, 0, 0, PM_REMOVE ) )
        {
            TranslateMessage( &messages );
            DispatchMessage( &messages );
        }

        else
        {
            // Render the frame.
            Direct3D.Render( );
        }
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    switch( message )                  /* handle the messages */
    {
        case WM_DESTROY:
            Direct3D.Finalize( );
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;

        case WM_KEYDOWN:
            switch( wParam )
            {
                case VK_ESCAPE:
                    Direct3D.Finalize( );
                    break;
            }
            break;

        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}


That's all I've got.
closed account (zb0S216C)
Fixed it.
Topic archived. No new replies allowed.