C++ 错误 LNK2019:未解析的外部符号“公共:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4790751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 16:30:55  来源:igfitidea点击:

error LNK2019: unresolved external symbol "public:

c++visual-studio-2008

提问by amrit_neo

I am creating an torrent application using libtorrent in VS 2008. I tried the example given in the link http://www.rasterbar.com/products/libtorrent/examples.htmlBUt it is showing me these error....how to solve them?

我正在 VS 2008 中使用 libtorrent 创建一个 torrent 应用程序。我尝试了链接http://www.rasterbar.com/products/libtorrent/examples.html 中给出的示例,但 它向我显示了这些错误......如何解决他们?

Linking...
main.obj : error LNK2019: unresolved external symbol "public: __thiscall libtorrent::torrent_info::~torrent_info(void)" (??1torrent_info@libtorrent@@QAE@XZ) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: __thiscall libtorrent::torrent_info::torrent_info(struct libtorrent::lazy_entry const &)" (??0torrent_info@libtorrent@@QAE@ABUlazy_entry@1@@Z) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "class std::basic_ostream > & __cdecl libtorrent::operator<<(class std::basic_ostream > &,struct libtorrent::lazy_entry const &)" (??6libtorrent@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV12@ABUlazy_entry@0@@Z) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "int __cdecl libtorrent::lazy_bdecode(char const *,char const *,struct libtorrent::lazy_entry &,int)" (?lazy_bdecode@libtorrent@@YAHPBD0AAUlazy_entry@1@H@Z) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall libtorrent::lazy_entry::clear(void)" (?clear@lazy_entry@libtorrent@@QAEXXZ) referenced in function "public: __thiscall libtorrent::lazy_entry::~lazy_entry(void)" (??1lazy_entry@libtorrent@@QAE@XZ)
main.obj : error LNK2019: unresolved external symbol "void __cdecl libtorrent::to_hex(char const *,int,char *)" (?to_hex@libtorrent@@YAXPBDHPAD@Z) referenced in function "class std::basic_ostream > & __cdecl libtorrent::operator<<(class std::basic_ostream > &,class libtorrent::big_number const &)" (??6libtorrent@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV12@ABVbig_number@0@@Z)
main.obj : error LNK2019: unresolved external symbol "public: struct libtorrent::peer_request __thiscall libtorrent::file_storage::map_file(int,__int64,int)const " (?map_file@file_storage@libtorrent@@QBE?AUpeer_request@2@H_JH@Z) referenced in function "public: struct libtorrent::peer_request __thiscall libtorrent::torrent_info::map_file(int,__int64,int)const " (?map_file@torrent_info@libtorrent@@QBE?AUpeer_request@2@H_JH@Z)
C:\Users\photoshop3\Documents\Visual Studio 2008\Projects\Lib2\Debug\Lib2.exe : fatal error LNK1120: 7 unresolved externals

回答by KaiserJohaan

The .lib is not included in your project. Make sure you are linking it in; Configuration Properties -> Linker -> Input -> Additional Dependencies

.lib 不包含在您的项目中。确保你正在链接它;配置属性 -> 链接器 -> 输入 -> 附加依赖项

Another altnerative is to simply copy the .lib to your project folder but don't, it's bound to create problems later on.

另一种选择是简单地将 .lib 复制到您的项目文件夹中,但不要这样做,以后肯定会产生问题。

Sometimes the .lib is not shipped with the library, so you need to compile it yourself. The README will tell you this. If this is the case, they usually ship with a .sln file you can open and the just compile it into a .lib file which you then reference in your main application, as I wrote above

有时 .lib 不随库一起提供,因此您需要自己编译它。README 会告诉你这一点。如果是这种情况,它们通常会附带一个 .sln 文件,您可以打开并将其编译成一个 .lib 文件,然后您可以在主应用程序中引用该文件,正如我上面写的

回答by Rui Teng

Have you added the path of header files in the "Configuration Properties" --> "C/C++“ --> "General" --> "Additional Include Directories"?

您是否在“配置属性”-->“C/C++”-->“常规”-->“附加包含目录”中添加了头文件的路径?

回答by harper

The linkgives you only the sources (including headerfiles) of libtorrent. You should compile this sources to get a .lib file. Add this .lib file to your client:

链接仅为您提供 libtorrent 的来源(包括头文件)。您应该编译此源以获取 .lib 文件。将此 .lib 文件添加到您的客户端:

Configuration Properties/Linker/Input -> Additional Dependencies: libtorrent-rasterbar.lib

配置属性/链接器/输入 -> 附加依赖项: libtorrent-rasterbar.lib

The best starting point for compiling should be the README file.

编译的最佳起点应该是 README 文件。

回答by Jerry Coffin

public:isn't the unresolved symbol. It's just there because the linker it trying to tell you that (most) of the unresolved symbols are public member functions.

public:不是未解决的符号。之所以存在,是因为链接器试图告诉您(大多数)未解析的符号是公共成员函数。

It looks like you've included the header for "libtorrent", but not linked to the "libtorrent" library.

看起来您已经包含了“libtorrent”的标题,但没有链接到“libtorrent”库。

回答by 341008

You have probably not linked with the torrent library or specified the wrong path to it so that the linker cannot find it.

您可能没有链接到 torrent 库或指定了错误的路径以致链接器无法找到它。

回答by ashwini

If the input libraries are of 32bit and your are using them in building a 64bit it might be one of the reasons

如果输入库是 32 位的并且您在构建 64 位时使用它们,这可能是原因之一

回答by Michele

For me, I had it included in my project, but it turned out that it was a plugin that was designed to not create an instance of in my unit test.

对我来说,我将它包含在我的项目中,但结果证明它是一个插件,旨在不在我的单元测试中创建实例。