错误LNK2019:无法解析的外部符号“公众:

问题描述:

我正在VS 2008中使用libtorrent创建一个torrent应用程序。我试过链接中给出的示例http://www.rasterbar.com/products/libtorrent/examples.html 它是向我展示这些错误....如何解决它们?错误LNK2019:无法解析的外部符号“公众:

Linking... 
main.obj : error LNK2019: unresolved external symbol "public: __thiscall libtorrent::torrent_info::~torrent_info(void)" ([email protected]@@[email protected]) referenced in function _main 
main.obj : error LNK2019: unresolved external symbol "public: __thiscall libtorrent::torrent_info::torrent_info(struct libtorrent::lazy_entry const &)" ([email protected]@@[email protected][email protected]@@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 &)" ([email protected]@[email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected]@@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)" ([email protected]@@[email protected]@[email protected]) referenced in function _main 
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall libtorrent::lazy_entry::clear(void)" ([email protected][email protected]@@QAEXXZ) referenced in function "public: __thiscall libtorrent::lazy_entry::~lazy_entry(void)" ([email protected]@@[email protected]) 
main.obj : error LNK2019: unresolved external symbol "void __cdecl libtorrent::to_hex(char const *,int,char *)" ([email protected]@@[email protected]) referenced in function "class std::basic_ostream > & __cdecl libtorrent::operator<<(class std::basic_ostream > &,class libtorrent::big_number const &)" ([email protected]@[email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected]@@Z) 
main.obj : error LNK2019: unresolved external symbol "public: struct libtorrent::peer_request __thiscall libtorrent::file_storage::map_file(int,__int64,int)const " ([email protected][email protected]@@[email protected]@[email protected]) referenced in function "public: struct libtorrent::peer_request __thiscall libtorrent::torrent_info::map_file(int,__int64,int)const " ([email protected][email protected]@@[email protected]@[email protected]) 
C:\Users\photoshop3\Documents\Visual Studio 2008\Projects\Lib2\Debug\Lib2.exe : fatal error LNK1120: 7 unresolved externals 

.lib未包含在您的项目中。确保你在链接它; 配置属性 - >链接器 - >输入 - >其他依赖关系

另一种方法是将.lib简单地复制到项目文件夹中,但不要,它必然会在稍后创建问题。

有时.lib没有附带库,所以你需要自己编译它。自述文件会告诉你这一点。如果是这种情况,他们通常会附带一个.sln文件,您可以打开该文件并将其编译为一个.lib文件,然后在主应用程序中引用该文件,因为我上面写过

public:不是解决的符号。它只是存在,因为它试图链接告诉你,(大多数)未解决的符号是公共成员函数。

看起来你已经包括“libtorrent”的标题,但未链接到“libtorrent”库。

+0

yes我正在使用libtorrent&在LInker> General> Additional Library目录中添加了:C:\ boost \ boost_1_36_0 \ stage \ lib; “C:\ Users \ photoshop3 \ Documents \ Visual Studio 2008 \ Projects \ Lib2 \ libtorrent”我还需要做什么? – 2011-01-25 07:05:20

+0

@amrit_neo:您也必须在项目设置中添加正确的库文件。 [项目属性|配置属性|链接器|输入|额外的依赖关系] – 2011-01-25 07:08:40

+0

对不起,但我是VS和这个libtorrent的新手。我应该添加哪一个。以前我创建了一个嵌入了浏览器的应用程序,我添加了comctl32.lib。添加这个仍然不能解决我的问题 – 2011-01-25 07:13:00

您可能未与torrent文件库链接或指定错误路径,以致链接程序找不到它。

+0

是的我正在使用libtorrent&在LInker>常规>附加库目录中添加了:C:\ boost \ boost_1_36_0 \ stage \ lib; “C:\ Users \ photoshop3 \ Documents \ Visual Studio 2008 \ Projects \ Lib2 \ libtorrent”我还需要做什么? – 2011-01-25 07:07:28

你有没有添加的头文件的路径在“配置属性” - >“C/C++“ - >‘常规’ - >‘附加包含目录’

link只给你? 。来源(包括headerfiles)libtorrent的你应该编译这个来源得到的.lib文件,这个的.lib文件添加到您的客户端:

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

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

如果输入库是32位和你正在使用它们在建立一个64位这可能是其中一个原因

对我来说,我把它包括在我的项目,但事实证明,它是一个插件,旨在不创建在我的单元测试中。