好LNK2001
The good ol' LNK2001
本文关键字:LNK2001 更新时间:2023-10-16
>我有 3 个标题DirectX.h
,Draws.h
,Memory.h
d
每个函数在其相应的.cpp中都有一个定义,因此除了 DirectX.h ofc 之外,该定义被排除在外 我尝试了一组解决方案来修复它,但没有成功,例如在标题上没有including
stdafx.h。
三者的一小部分
内存.h
#pragma once
#include "stdafx.h"
Class Memory
{
foo..
};
extern Memory *gMemory;
平局.h
#pragma once
#include "stdafx.h"
Class Drawing
{
foo..
};
extern Drawing *Draw;
DirectX.h
#pragma once
#include "stdafx.h"
struct Direct
{
foo
};
extern Direct *DirectX;
错误
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
#include <windows.h>
#include <iostream>
#include <d3d9.h>
#include <d3dx9.h>
#include "Memory.h"
#include "Draws.h"
#include "DirectX.h"
dllmain.cpp我使用extern的唯一部分是
gMemory->FindPattern(..);
if (!DirectX->Line)
{
D3DXCreateLine(pDevice, &DirectX->Line);
}
Draw->Circle(foo);
>extern
关键字意味着该对象是在其他地方定义的(在其他编译单元中,在链接的静态库中(,简而言之,它是指向对象的链接,这些对象在其他地方实例化(创建(,但可以在当前编译单元中使用。
在dllmain.cpp
中,您应该在全局(例如(范围内声明变量:
// Declaration of pointers.
Drawing* Draw = NULL;
Direct* DirectX = NULL;
Memory* gMemory = NULL;
在int dllmain()
(或您拥有的任何主要功能(中:
// Initialization of pointers with newly created objects:
Draw = new Drawing();
DirectX = new Direct();
gMemory = new Memory();
相关文章:
- 为什么我的 heap.h 文件给我一个LNK2001错误?
- 将QT项目导入Visual Studio 2019会给我带来很多LNK2001错误
- 我收到错误LNK2001:未解析的外部符号(C++代码)
- Dlib LNK2001未解析的外部符号USER_ERROR__consistent_build_configurati
- LNK2001:未解析的外部符号public:static类std::vector
- 使用模板成员函数时出现LNK2001错误
- 错误 LNK2001:未解析的外部符号"private: static class Game Game::game_"
- LNK2001尝试将我的主函数分离为主.cpp时,我有一个奇怪的错误
- C++、错误LNK1120和LNK2001中未解析的外部符号
- 好LNK2001
- LNK2001 SHA3 类成员的未解析外部符号
- 错误 LNK2001:VS2017 中未解析的外部符号___iob_func
- 使用外部变量会导致"unsigned char"错误LNK2001
- Dlib错误LNK2001未解析的外部符号
- 为什么 VS C++链接器返回具有混合 DLL 转发的"LNK2001: unresolved external symbol"?
- VTK / ITK/ QT - 未解决的外部符号错误 (LNK2001)
- 互联网引起链接器错误lnk1120和lnk2001
- 使用boost::numpy时LNK2001错误
- LNK2001在X64环境中的编译代码上看到的错误.但是,该代码在X86环境中填充了罚款
- 在其他项目的派生类中,在LNK2001中未出现的虚拟函数在LNK2001中产生