问题描述
我有多个项目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)
一切似乎是罚款。我看到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:在多个项目的解决方案解析的外部符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!