在Visual Studio中编码时,我得到了一个未解决的外部符号错误 我不知道该怎么办我不知道怎么了。 你能帮我破译一下吗?我应该在哪里寻找什么样的错误?

1>Form.obj : error LNK2019: unresolved external symbol "public: class Field * __thiscall Field::addField(class Field *)" (?addField@Field@@QAEPAV1@PAV1@@Z) referenced in function "public: void __thiscall Form::parse(class std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?parse@Form@@QAEXAAV?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>Form.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall Field::parse(class std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?parse@Field@@UAEXAAV?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: __thiscall InputField::InputField(class std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> > &)" (??0InputField@@QAE@AAV?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Field::prompt(void)" (?prompt@Field@@UAEXXZ)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Field::getName(void)" (?getName@Field@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Field::getType(void)" (?getType@Field@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Field::describe(void)" (?describe@Field@@UAEXXZ)
1>C:\Users\tomy\Documents\Visual Studio 2010\Projects\zapoctovkac++\Debug\zapoctovkac++.exe : fatal error LNK1120: 6 unresolved externals

当前回答

我有一个错误,我的项目被编译为x64项目。我使用的库是x86编译的。

我重新编译了x64库,它解决了这个问题。

其他回答

我的问题是:我必须对一个“外部未解决”的课程做前向声明。

在我得到错误的文件中,我必须放这样的东西:

#include "ClassB" 

class ClassB; // this solved the problem

class ClassA{
    void foo(){
        ClassB* tmp = new ClassB();
        // ...
    }
};

当然,我的项目要复杂得多,这只是一个片段示例。同样,在使用名称空间时,也要声明它们。

确保你用

#ifndef YOUR_HEADER_H
#define YOUR_HEADER_H

// your header code here

#endif

如果你不这样做,就会发生不好的事情,包括这件事

这是另一种检查的可能性,这次是我的问题。

我已经将函数添加到库中,并将库的输出文件夹包含在搜索路径中。

但是我也有一个文件夹,里面有之前列出的旧版本的库,所以VS使用的是旧的库,当然没有找到新函数。

我刚刚也犯了同样的错误,我设法通过替换来避免它;头文件中使用{}。

#ifndef XYZ_h
#define XYZ_h
class XYZ
{
    public:
    void xyzMethod(){}
}
#endif

当它是void xyzMethod();它不想编译。

我也有同样的问题。在我取出最新的代码后,我的程序一天还能工作,第二天就不行了。

最新的代码不包括我在库中引用的项目。所以当我重建我的库时,它删除了。obj文件,whoopsy.....

我重新包含了我需要的项目,建立了我的库,然后重建了我的失败的项目,它运行得很好。

这个故事的寓意是,在深入到兔子洞之前,验证你的.obj文件是你引用它的地方。