C++ 好的ol';LNK2001
我有3个标题C++ 好的ol';LNK2001,c++,header,linker,C++,Header,Linker,我有3个标题 DirectX.h,Draws.h,Memory.hd 每个函数在其对应的.cpp中都有一个定义,因此排除了DirectX.h ofc之外的定义 我尝试了一套解决方案来修复它,但没有成功,比如在标题上的all中不包含includestdafx.h 这三个故事的一小部分 内存.h #pragma once #include "stdafx.h" Class Memory { foo..
DirectX.h
,Draws.h
,Memory.h
d
每个函数在其对应的.cpp中都有一个定义,因此排除了DirectX.h ofc之外的定义
我尝试了一套解决方案来修复它,但没有成功,比如在标题上的all中不包含include
stdafx.h
这三个故事的一小部分
内存.h
#pragma once
#include "stdafx.h"
Class Memory
{
foo..
};
extern Memory *gMemory;
#pragma once
#include "stdafx.h"
Class Drawing
{
foo..
};
extern Drawing *Draw;
#pragma once
#include "stdafx.h"
struct Direct
{
foo
};
extern Direct *DirectX;
#include <windows.h>
#include <iostream>
#include <d3d9.h>
#include <d3dx9.h>
#include "Memory.h"
#include "Draws.h"
#include "DirectX.h"
绘制.h
#pragma once
#include "stdafx.h"
Class Memory
{
foo..
};
extern Memory *gMemory;
#pragma once
#include "stdafx.h"
Class Drawing
{
foo..
};
extern Drawing *Draw;
#pragma once
#include "stdafx.h"
struct Direct
{
foo
};
extern Direct *DirectX;
#include <windows.h>
#include <iostream>
#include <d3d9.h>
#include <d3dx9.h>
#include "Memory.h"
#include "Draws.h"
#include "DirectX.h"
DirectX.h
#pragma once
#include "stdafx.h"
Class Memory
{
foo..
};
extern Memory *gMemory;
#pragma once
#include "stdafx.h"
Class Drawing
{
foo..
};
extern Drawing *Draw;
#pragma once
#include "stdafx.h"
struct Direct
{
foo
};
extern Direct *DirectX;
#include <windows.h>
#include <iostream>
#include <d3d9.h>
#include <d3dx9.h>
#include "Memory.h"
#include "Draws.h"
#include "DirectX.h"
错误
1>dllmain.obj : error LNK2001: unresolved external symbol "class Memory * gMemory" (?gMemory@@3PAVMemory@@A)
1>dllmain.obj : error LNK2001: unresolved external symbol "class Drawing * Draw" (?Draw@@3PAVDrawing@@A)
1>dllmain.obj : error LNK2001: unresolved external symbol "struct Direct * DirectX" (?DirectX@@3PAUDirect@@A)
1>Draws.obj : error LNK2001: unresolved external symbol "struct Direct * DirectX" (?DirectX@@3PAUDirect@@A)
stdafx.h
#pragma once
#include "stdafx.h"
Class Memory
{
foo..
};
extern Memory *gMemory;
#pragma once
#include "stdafx.h"
Class Drawing
{
foo..
};
extern Drawing *Draw;
#pragma once
#include "stdafx.h"
struct Direct
{
foo
};
extern Direct *DirectX;
#include <windows.h>
#include <iostream>
#include <d3d9.h>
#include <d3dx9.h>
#include "Memory.h"
#include "Draws.h"
#include "DirectX.h"
extern
关键字意味着,该对象是在其他地方定义的(在其他编译单元中,在链接的静态库中),简单地说,它是指向在其他地方实例化(创建)但可在当前编译单元中使用的对象的链接
在dllmain.cpp
中,您应该在全局(例如)范围内声明变量:
在int dllmain()
(或任何您拥有的主要功能)中:
向我们显示dllmain.cpp。似乎,您从未使用
extern
定义对象gMemory
,Draw
和DirectX
,但这并不会创建变量。它们是在别的地方申报的吗?不,它们不是,那么我应该怎么做才能使用extern呢?在变量之前声明它们,外部变量?好的,但我在绘图时使用。h如何将对象范围扩展到该范围?extern Drawing*Draw
已经做了您想要的事情:对象将在dllmain.cpp
中声明,但在Drawing.h
tooThanks中可用,这对我来说真的很清楚!