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 9208251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:34:35+00:00 2026-06-18T00:34:35+00:00

I was trying to do a DirectX tutorial, but I wanted to write the

  • 0

I was trying to do a DirectX tutorial, but I wanted to write the application in C and not in C++. So I wrote the code in C, but when I tried to compile it I got lot’s of errors on the “setupD3D” function. So I just renamed a file to .cpp. But the new code didn’t compile either. I think that combining C and C++ is the problem, or there are to many cross-references. Can anyone tell me what the problem is in this code?

direct3d.h:

#include "main.h"

#ifndef DIRECT3D

#define DIRECT3D

int m_videoCardMemory;
char m_videoCardDescription[128];
ID3D11DeviceContext* m_deviceContext = 0;
D3DXMATRIX m_projectionMatrix;
D3DXMATRIX m_worldMatrix;
D3DXMATRIX m_orthoMatrix;

int setupD3D(BYTE vsync, HWND hwnd, float screenDepth, float screenNear);
void terminateD3D();
void beginScene(float red, float green, float blue, float alpha);
void endScene();

#endif

direct3d.cpp

#include "direct3d.h"
// code

main.h:

#ifndef MAIN_FUNC

#define MAIN_FUNC

#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dx11.lib")
#pragma comment(lib, "d3dx10.lib")

#include <Windows.h>
#include <dxgi.h>
#include <d3dcommon.h>
#include <d3d11.h>
#include <d3dx10math.h>
#include "direct3d.h"

int breedte, hoogte;
LRESULT CALLBACK Actie(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
void main_loop(MSG* msg);
void keyevent();

#endif

main.c

#include "main.h"
// code

winstart.c

#include "main.h"
// code

Errors:

Error   86  error LNK2005: _m_deviceContext already defined in main.obj
Error   87  error LNK2019: unresolved external symbol _setupD3D referenced in function _Actie@16
Error   88  error LNK2019: unresolved external symbol _terminateD3D referenced in function _Actie@16
Error   89  error LNK2019: unresolved external symbol _beginScene referenced in function _render
Error   90  error LNK2019: unresolved external symbol _endScene referenced in function _render
Error   91  error LNK1120: 4 unresolved externals   

I also have 84 warnings about macro redefinitions.

  • 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-06-18T00:34:36+00:00Added an answer on June 18, 2026 at 12:34 am

    If you declare functions in a .cpp file the compiler will compile it as C++ code (no matter if it’s pure C or not). Unfortunately C++ has a mechanism called Name mangling which allows for example overloading of functions while C doesn’t. If you now want to call such a function fro a .c file (which is recognized as pure C by the compiler) the compiler is creating references for another naming of the symbols (functions in your case) than they exist and the linker is not able to match them anymore.

    To solve this, you can put an extern "C" in front of every function you want to be callable by C. As C does not recognize extern "C" you have to make this language dependent.

    A common way to solve this problem is to bring follwing structure in the header file:

    ... your include guard of choice
    
    #ifdef __cplusplus
        extern "C" {
    #endif
    
    //-- your declarations
    
    #ifdef __cplusplus
        }
    #endif
    

    This instructs the C++ compiler to create names that are C compliant. As the C compiler does not provide the preprocessor symbol “__cplusplus” it ignores the extern statement. (Which is ok as the C compiler always only creates C compliant symbol names)

    Instead of changing header files (sometimes you are not allowed to) it’s also legal to include a whole header file embraced by extern "C":

    extern "C" {
        #include <My_C_API.h>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a media player application with DirectX.AudioVideoPlayback, but when I try
I am trying to initialize directX, but for some reason it can't create d3d
I'm trying to setup DirectX on Visual C++ 2010 express. I do not have
i'm trying to make this code snippet from the sinatra tutorial work so that
I'm trying to follow Riemer's DirectX with C++ tutorial . I have made a
Don't know if I'm over-thinking this or not.. but I'm trying to be able
I'm new to android but I've done the notepad tutorial. Now I'm trying to
I'm trying to write a small chunk of code to grab the backbuffer into
I am trying to learn some DirectX API and, for now, I have just
I am new to DirectX and I am trying to draw two rectangles in

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.