VC++中的错误LNK2019和LNK2028;快报2008

发布于 2024-12-26 06:14:53 字数 1002 浏览 5 评论 0原文

我正在尝试构建一个包含 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫漫岁月 2025-01-02 06:14:53

这两个项目都有一个主要功能吗?

这意味着您正在构建两个可执行文件。可执行文件通常不导出函数。

您需要一个可执行文件和一个类库 (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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文