错误LNK2019:​​在多个项目的解决方案解析的外部符号 [英] error LNK2019: unresolved external symbol in a multiple projects solution

查看:142
本文介绍了错误LNK2019:​​在多个项目的解决方案解析的外部符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个项目Visual Studio解决方案。他们中的一个,MyProject的是一个静态库(.LIB)。该项目的许多其他类中有两类A和B。

I have a visual studio solution with multiple projects. One of them, "MyProject" is a static library (.lib). The project, among many other classes has two classes "A" and "B".

A.H:

#pragma once

class A
{
public:
    void foo();
};

A.cpp:

#include A.h

void A::foo(){
        //do something
}

B.h:

#pragma once

class B
{
public:
    void bar();
};

B.cpp:

#include B.h
#include A.h

void B::bar(){
        A a;
        a.foo();
}

如果没有编译错误,我得到的链接错误:

Without compilation errors I'm getting the linkage error:

OtherProject.lib(B.OBJ):错误LNK2019:​​无法解析的外部符号市民:无效__thiscall
  A :: foo的(无效),在函数引用(foo的@一@@ QAE_NXZ?)市民:无效
  __thiscall B ::巴(无效)(?巴@乙@@ QAEXXZ)

OtherProject.lib(B.obj) : error LNK2019: unresolved external symbol "public: void __thiscall A::foo(void)" (?foo@A@@QAE_NXZ) referenced in function "public: void __thiscall B::bar(void)" (?bar@B@@QAEXXZ)

一切似乎是罚款。我看到A.cpp的编译过程。大厦或链接只有项目MyProject的是好的。但是,当试图生成整个解决方案,我发现了错误。

Everything seems to be fine. I do see the compilation process of A.cpp. Building or linking only the project "MyProject" is fine. But when trying to build the whole solution I'm getting the error.

谢谢!

推荐答案

事实证明,还有一个项目 OtherProject ,其中包括类 B 并使用它的功能巴()。我没有读错误不够好,并没有注意到,在另一个项目中出现链接错误。所有我必须做的是包括 A.cpp OtherProject

It turns out that, there is another project OtherProject that includes class B and uses it's function bar(). I didn't read the error good enough and didn't notice that the linkage error occurs in another project. All I had to do is include A.cpp in OtherProject.

这篇关于错误LNK2019:​​在多个项目的解决方案解析的外部符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆