Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4593290
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:39:44+00:00 2026-05-21T22:39:44+00:00

I’m trying to follow Riemer’s DirectX with C++ tutorial . I have made a

  • 0

I’m trying to follow Riemer’s DirectX with C++ tutorial.

I have made a few changes, for example here I have made my InitializeDevice() function in a separate file (tdirect.cpp / tdirect.h).

When I press F5 to compile and run, the program works perfectly. But when I make a change to a value (e.g. 0xff00ffff to 0xff0000ff – cyan to blue) without choosing the “Rebuild” option I get a stream of errors in my console which prevent me from compiling the program. This is pretty annoying as you can imagine. It’s as if it’s compiling tdirect.cpp twice.

Here’s the source code of tdirect.cpp, tdirect.h, and the relevant part from main.cpp (tdirect.h is only included from main.cpp, and basicvertex.h is only included from tdirect.cpp)

tdirect.cpp:

#include "tdirect.h"
#include "basicvertex.h"

IDirect3D9 *pD3D;
D3DPRESENT_PARAMETERS D3DParams; 

LPDIRECT3DDEVICE9 InitializeDevice(HWND Wnd)
{
    pD3D = Direct3DCreate9(D3D_SDK_VERSION);
    if (pD3D == NULL)
    {
        MessageBox(Wnd, "DirectX is not installed.", "No DirectX!", MB_OK);
        return NULL;
    }

    ZeroMemory(&D3DParams, sizeof(D3DPRESENT_PARAMETERS));

    D3DParams.Windowed = TRUE;
    D3DParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
    D3DParams.BackBufferFormat = D3DFMT_UNKNOWN;

    LPDIRECT3DDEVICE9 pDevice;
    if (FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Wnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &D3DParams, &pDevice)))
    {
        if (FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, Wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &D3DParams, &pDevice)))
        {
            MessageBox(Wnd, "Failed to create reference device.", "No software device!", MB_OK);
        }
        else {
            MessageBox(Wnd, "Falling back to software mode.", "No hardware device!", MB_OK);
        }
    }

    return pDevice;
}

LPDIRECT3DVERTEXBUFFER9 vBuffer;
void Init(LPDIRECT3DDEVICE9 pDevice)
{
    BASICVERTEX Vertices[3];
    Vertices[0].x = 150;
    Vertices[0].y = 100;
    Vertices[0].weight = 1;
    Vertices[0].colour = 0xffff0000;

    Vertices[1].x = 350;
    Vertices[1].y = 100;
    Vertices[1].weight = 1;
    Vertices[1].colour = 0xff00ff00;

    Vertices[2].x = 250;
    Vertices[2].y = 300;
    Vertices[2].weight = 1;
    Vertices[2].colour = 0xff00ffff;

    if (FAILED(pDevice->CreateVertexBuffer(sizeof(BASICVERTEX)*3, 0, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &vBuffer, NULL)))
    {
        MessageBox(NULL, "Failed to create vertex buffer", "Fail", MB_OK);
    }
    else {
        void* pVertices;
        if (FAILED(vBuffer->Lock(0, sizeof(BASICVERTEX)*3, (void**)&pVertices, 0)))
        {
            MessageBox(NULL, "Failed to lock vertex buffer", "Fail", MB_OK);
        }
        else {
            memcpy(pVertices, Vertices, sizeof(BASICVERTEX)*3);
            vBuffer->Unlock();
        }
    }
}

void DrawScene(LPDIRECT3DDEVICE9 pDevice)
{
    pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
    pDevice->BeginScene();

    pDevice->SetStreamSource(0, vBuffer, 0, sizeof(BASICVERTEX));
    pDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
    pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

    pDevice->EndScene();
    pDevice->Present(NULL, NULL, NULL, NULL);
}

tdirect.h:

#pragma once
#include <Windows.h>

main.cpp include part:

#include <Windows.h>

#include "dxheader.h"
#include "tdirect.cpp"

Compiler Errors:

1>Debug\tdirect.obj : warning LNK4042: object specified more than once; extras ignored
1>main.obj : error LNK2005: "struct IDirect3DDevice9 * __cdecl InitializeDevice(struct HWND__ *)" (?InitializeDevice@@YAPAUIDirect3DDevice9@@PAUHWND__@@@Z) already defined in tdirect.obj
1>main.obj : error LNK2005: "void __cdecl Init(struct IDirect3DDevice9 *)" (?Init@@YAXPAUIDirect3DDevice9@@@Z) already defined in tdirect.obj
1>main.obj : error LNK2005: "void __cdecl DrawScene(struct IDirect3DDevice9 *)" (?DrawScene@@YAXPAUIDirect3DDevice9@@@Z) already defined in tdirect.obj
1>main.obj : error LNK2005: "struct IDirect3DVertexBuffer9 * vBuffer" (?vBuffer@@3PAUIDirect3DVertexBuffer9@@A) already defined in tdirect.obj
1>main.obj : error LNK2005: "struct _D3DPRESENT_PARAMETERS_ D3DParams" (?D3DParams@@3U_D3DPRESENT_PARAMETERS_@@A) already defined in tdirect.obj
1>main.obj : error LNK2005: "struct IDirect3D9 * pD3D" (?pD3D@@3PAUIDirect3D9@@A) already defined in tdirect.obj
1>C:\Users\me\Documents\Visual Studio 2010\Projects\DirectX\Debug\DXStuff.exe : fatal error LNK1169: one or more multiply defined symbols found

Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T22:39:45+00:00Added an answer on May 21, 2026 at 10:39 pm

    You’re including an implementation file from your main.cpp, so it’s adding the functions in again. You can’t do this:

     #include "tdirect.cpp"
    

    Instead you need to create a header file with the function prototypes so you can reference them…

    Do you have these defined in your “tdirect.h” (this is what main.cpp should be including)?

    LPDIRECT3DDEVICE9 InitializeDevice(HWND Wnd);
    

    etc…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.