c++ 中的链接错误& DirectX 文件包含问题
我有两个头文件:
DirectX_Engine.h
#pragma once
#include "Main.h"
#include <d3d9.h>
和:
Main.h
#pragma once
#include <Windows.h>
#include "DirectX_Engine.h"
int imRunning = 1;
编译后,我收到以下链接器错误:
error LNK1169: one or more multiply defined symbols found
error LNK2005: "int imRunning" (?imRunning@@3HA) already defined in DirectX_Engine.obj
我还收到“文件未找到或#include
“d3dx9.h”时出现目录不存在错误。有什么想法吗?
I have two header files:
DirectX_Engine.h
#pragma once
#include "Main.h"
#include <d3d9.h>
and:
Main.h
#pragma once
#include <Windows.h>
#include "DirectX_Engine.h"
int imRunning = 1;
After compiling, I get the following linker errors:
error LNK1169: one or more multiply defined symbols found
error LNK2005: "int imRunning" (?imRunning@@3HA) already defined in DirectX_Engine.obj
I'm also getting a 'file is not found or directory doesn't exist error' when #include
ing "d3dx9.h". Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两个想法。首先,将
DirectX_Engine.h
包含在Main.h
中,并将Main.h
包含在DirectX_Engine.h
中。这显然行不通。其次,
int imRunning
被包含到每个包含Main.h
的 .cpp 文件中,并且编译器将其视为定义。然后链接器看到每个文件中定义的imRunning
并且不知道该怎么做。解决方案是使用 extern:在
Main.h
中:在其中一个 .cpp 文件中:
Two ideas. Firstly, you are including
DirectX_Engine.h
inMain.h
andMain.h
inDirectX_Engine.h
. This will obviously not work.Secondly,
int imRunning
gets included to each .cpp file that includesMain.h
and the compiler treats it as a definition. Then the linker comes and seesimRunning
defined in each of these files and doesn't know what to do. The solution is using extern:In
Main.h
:In one of the .cpp files:
d3dx9.h 不附带 VS 或 Platform SDK。您需要返回 MSDN 下载并获取 DirectX SDK。
d3dx9.h doesn't come with VS or Platform SDK. You'll need to go back to MSDN downloads and get DirectX SDK.