我试图做一个 DirectX 教程,但我想用 C 而不是 C++ 编写应用程序。所以我用 C 编写了代码,但是当我尝试编译它时,“setupD3D”函数出现了很多错误。所以我只是将一个文件重命名为.cpp。但是新代码也没有编译。我认为将 C 和 C++ 结合起来是问题所在,或者有很多交叉引用。谁能告诉我这段代码有什么问题?
直接3d.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
直接3d.cpp
#include "direct3d.h"
// code
主.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
主程序
#include "main.h"
// code
winstart.c
#include "main.h"
// code
错误:
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
我还有 84 条关于宏重定义的警告。