每次更改代码后都无法解析外部符号

发布于 2024-11-26 23:13:56 字数 919 浏览 0 评论 0原文

我的代码有问题。它基本上看起来像这样:

someclass.hpp:

class SomeClass
{
 public:
    SomeClass();
    ~SomeClass();

    //... some other methods
};

someclass.cpp:

#include "SomeClass.hpp"
SomeClass::SomeClass()
{
}

SomeClass::~SomeClass()
{
}

SomeClass.cpp 不包含其他任何内容。

构造函数实际上也是空的。我只是不想让它们未定义或保留标准构造函数,因为我稍后可能会需要它。

SomeClass.hpp 实际上是一个游戏状态类,仅包含在一个位置:

main.cpp

#include "SomeClass.hpp"

int main()
{
   DoSomethingWithGamestate(new SomeClass());
   return 0;
}

然后该项目由许多其他文件组成,但所有这些文件都独立于 SomeClass。

问题是,每当我更改代码中的任何内容时,无论在哪个文件中,我都必须重新编译整个解决方案,因为如果我只编译更改,链接器会抛出以下错误:

error LNK2001: unresolved external symbol "public: __thiscall SomeClass::SomeClass(void) (??blablaSomeClassblabla)

显然,这里发生了一些奇怪的事情,因为 SomeClass()在 someclass.cpp 中明确定义。

这可能是什么原因?

I've got a problem with my code. It basically looks like this:

someclass.hpp:

class SomeClass
{
 public:
    SomeClass();
    ~SomeClass();

    //... some other methods
};

someclass.cpp:

#include "SomeClass.hpp"
SomeClass::SomeClass()
{
}

SomeClass::~SomeClass()
{
}

SomeClass.cpp doesn't include anything else.

The constructors are actually empty, too. I just don't want to leave them undefined or leave the standard constructor because I'm probably going to need it later.

SomeClass.hpp is actually a gamestate class which is included in only one place:

main.cpp

#include "SomeClass.hpp"

int main()
{
   DoSomethingWithGamestate(new SomeClass());
   return 0;
}

And then the project consists of a lot of other files, all of which are independent from SomeClass, though.

The problem is that whenever I change anything in the code, no matter in which file, I have to recompile the entire solution because if I only compile the changes the linker throws this:

error LNK2001: unresolved external symbol "public: __thiscall SomeClass::SomeClass(void) (??blablaSomeClassblabla)

Obviously, there's something weird going on here, since SomeClass() is clearly defined in someclass.cpp.

What could be the source of this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

清旖 2024-12-03 23:13:56

除了 @Nawaz 所说的之外,您的构建文件可能与链接器不同步,因此当 Visual Studio 重新链接时,它不能,因为文件不同步。只需重新构建并完成即可。

顺便说一句,它甚至可能是 Visual Studio 2010 中的一个错误 如此处所示

In addition to what @Nawaz says, it's likely your build files are out of sync with the linker so that when Visual Studio goes to re-link, it can't because the files are out of sync. Just re-build and be done with it.

By the way, it may even be a bug in Visual Studio 2010 as seen here.

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