错误 LNK2019: 未解析的外部符号 "public:

6

我正在使用VS 2008和libtorrent创建一个种子应用程序。我尝试了链接中给出的示例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
7个回答

13

您的项目中没有包含 .lib 文件。请确保在以下位置进行链接:配置属性 -> 链接器 -> 输入 -> 附加依赖项。

另一种选择是将 .lib 文件简单地复制到您的项目文件夹中,但不建议这样做,因为稍后可能会引起问题。

有时候库并未随附 .lib 文件,因此您需要自己编译它。README 文档会告诉您如何操作。如果是这种情况,通常会附带一个 .sln 文件,您可以打开它并将其编译成一个 .lib 文件,然后在主应用程序中引用它,就像我上面所写的那样。


我添加了libtorrent-rasterbar.lib,但是出现错误:LINK:致命错误LNK1104:无法打开文件'libtorrent-rasterbar.lib',现在我该去哪里找它:( - amrit_neo
浏览您的libtorrent文件夹,看看文件是否存在。如果不存在,则需要自行编译。 - KaiserJohaan
文件不存在...如何编译它..请告诉我。 - amrit_neo

2

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


2
该链接仅提供libtorrent的源代码(包括头文件)。您需要编译这些源代码以获取.lib文件。将此.lib文件添加到您的客户端中:

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

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


如何创建libtorrent-rasterbar.lib?我在任何地方都找不到它。 - amrit_neo
在 README 中没有关于库创建的信息。我尝试了这个网址中提供的技术,但仍无法创建 lib 文件。 - amrit_neo
README 包含构建说明。(1)请参阅 docs/manual.html(2)运行:./configure然后执行:make - harper

1

public: 不是未解决的符号。它只是存在于那里,因为链接器试图告诉您大多数未解决的符号都是公共成员函数。

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


是的,我正在使用libtorrent,并在链接器>常规>附加库目录中添加了:C:\boost\boost_1_36_0\stage\lib; "C:\Users\photoshop3\Documents\Visual Studio 2008\Projects\Lib2\libtorrent"。还需要做什么? - amrit_neo
@amrit_neo:你还需要在项目设置中添加正确的库文件。【项目属性|配置属性|连接器|输入|附加依赖项】 - Jerry Coffin
抱歉,我对VS和这个libtorrent都不熟悉。我应该添加哪一个?之前我创建了一个嵌入浏览器的应用程序,在其中我添加了comctl32.lib。但是添加它仍然没有解决我的问题。 - amrit_neo

1

你可能没有链接到种子库,或者指定了错误的路径,导致链接器无法找到它。


是的,我正在使用libtorrent,并在链接器>常规>附加库目录中添加了:C:\boost\boost_1_36_0\stage\lib; "C:\Users\photoshop3\Documents\Visual Studio 2008\Projects\Lib2\libtorrent"。还需要做什么? - amrit_neo
我已经添加了头文件,但是我在哪里可以获取种子库? - amrit_neo
您可以从rasterbar软件的下载部分(http://www.rasterbar.com/products/libtorrent/index.html)下载所需的版本。 - 341008

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

0

对我来说,我已经将它包含在我的项目中,但结果发现它是一个插件,不应该在我的单元测试中创建实例。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接