VC++中的错误LNK2019和LNK2028;快报2008
我正在尝试构建一个包含 2 个项目的解决方案并获取以下错误消息:
ColliderTest.obj : error LNK2028: undefined token (0A000080) "public: __thiscall Rect::Rect(int)" (??0Rect@@$FQAE @XZ) 在函数“void __cdecl myFunction(void)”中引用 (?myFunction@@$FYAXXZ)
ColliderTest.obj : 错误 LNK2019: 函数“void __cdecl myFunction(void)” (?myFunction@@$$FYAXXZ) 中引用了无法解析的外部符号“public: __thiscall Rect::Rect(int)” (??0Rect@@$$FQAE@XZ) )
代码:
- 在项目“Collider”中我有这些文件:
Collider.h
#pragma once
class Rect{
int x;
int y;
unsigned int w;
unsigned int h;
public:
Rect(int x);
};
Collider.cpp
#include "Collider.h"
Rect::Rect(int x){
this->x = x;
}
- 项目“ColliderTest”有一个参考到项目 Collider,以及此文件:
ColliderTest.cpp
#include "../app/Collider.h"
void myFunction();
void myFunction(){
Rect rect(4);
}
另外,每个项目都有一个 main.cpp 文件,其中包含一个空的 main() 函数,以避免编译器对入口点的抱怨。
I'm trying to build a solution with 2 projects and get these error messages:
ColliderTest.obj : error LNK2028: undefined token (0A000080) "public: __thiscall Rect::Rect(int)" (??0Rect@@$$FQAE@XZ) referenced in function "void __cdecl myFunction(void)" (?myFunction@@$$FYAXXZ)
ColliderTest.obj : error LNK2019: unresolved external symbol "public: __thiscall Rect::Rect(int)" (??0Rect@@$$FQAE@XZ) referenced in function "void __cdecl myFunction(void)" (?myFunction@@$$FYAXXZ)
The code:
- In the project "Collider" I have these files:
Collider.h
#pragma once
class Rect{
int x;
int y;
unsigned int w;
unsigned int h;
public:
Rect(int x);
};
Collider.cpp
#include "Collider.h"
Rect::Rect(int x){
this->x = x;
}
- The project "ColliderTest" has a reference to the project Collider, and this file:
ColliderTest.cpp
#include "../app/Collider.h"
void myFunction();
void myFunction(){
Rect rect(4);
}
Also, each project has a main.cpp file with an empty main() function, to avoid the complains of the compiller about the entry point.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这两个项目都有一个主要功能吗?
这意味着您正在构建两个可执行文件。可执行文件通常不导出函数。
您需要一个可执行文件和一个类库 (dll)。
顺便说一句:如果你有一个空的 main 函数,你如何知道你的程序是否运行了?
Both projects have a main function?
That means you are building two executable. Executables typically do not export functions.
You need one executable and one class library (dll).
BTW: If you have an empty main function, how will you know if your program ran?