0

我有一个使用名为“解决方案”的 Visual Studio 2008 创建的解决方案,并且我在该解决方案中有两个项目,项目“ A ”和项目“ B ”。当我做下面这样的事情时,它会在底部显示致命错误。我在项目 A->properties->Additional include Directory as ../B 中给出

项目B

溴化氢

#include <iostream>

using namespace std;
class B
{
public:
    B();
    ~B();
};

B.cpp

#include "B.h"

B::B()
{

}

B::~B()
{

}

项目A

#include <iostream>

using namespace std;
class A
{
public:
    A();
    ~A();
};

A.cpp

#include "A.h"
#include "B.h"
A::A()
{
    B b;
}

A::~A()
{

}

项目 A 中的 Main.cpp

#include "B.h"

int main()
{
    B b;
    system("pause");
}

当我运行它说

错误 3 致命错误 LNK1120: 2 unresolved externals H:\Sol\Debug\A.exe

错误 2 错误 LNK2001: 无法解析的外部符号 "public: __thiscall B::B(void)" (??0B@@QAE@XZ) A.obj

错误 1 ​​错误 LNK2001: 无法解析的外部符号 "public: __thiscall B::~B(void)" (??1B@@QAE@XZ) A.obj

4

1 回答 1

1

看起来您不是从项目 B 中导出类 B。所以项目 A 看到了类 B 的声明,但找不到它的实现。项目 B 构建什么?

于 2010-03-05T02:03:54.777 回答