码迷,mamicode.com
首页 > 其他好文 > 详细

error LNK2019: 无法解析的外部符号

时间:2015-12-31 19:17:30      阅读:393      评论:0      收藏:0      [点我收藏+]

标签:

最近在尝试用UDT进行通信,写了两个简单的客户端和服务端,但是编译的时候出现了“error LNK2019: 无法解析的外部符号”错误,为了以后进行总结,还是把解决方法记录下来。

1>------ 已启动生成: 项目: udt_appserver, 配置: Debug Win32 ------
1>生成启动时间为 2013/11/11 20:53:08。
1>InitializeBuildStatus:
1>  正在创建“Debug\udt_appserver.unsuccessfulbuild”,因为已指定“AlwaysCreate”。
1>ClCompile:
1>  appserver.cpp
1>ResourceCompile:
1>  所有输出均为最新。
1>ManifestResourceCompile:
1>  所有输出均为最新。
1>api.obj : error LNK2019: 无法解析的外部符号 __imp__WSAGetLastError@0,该符号在函数 "public: int __thiscall CUDTUnited::startup(void)" (?startup@CUDTUnited@@QAEHXZ) 中被引用
1>channel.obj : error LNK2001: 无法解析的外部符号 __imp__WSAGetLastError@0
1>api.obj : error LNK2019: 无法解析的外部符号 __imp__WSAStartup@8,该符号在函数 "public: int __thiscall CUDTUnited::startup(void)" (?startup@CUDTUnited@@QAEHXZ) 中被引用
1>api.obj : error LNK2019: 无法解析的外部符号 __imp__WSACleanup@0,该符号在函数 "public: int __thiscall CUDTUnited::cleanup(void)" (?cleanup@CUDTUnited@@QAEHXZ) 中被引用
1>api.obj : error LNK2019: 无法解析的外部符号 __imp__getsockname@12,该符号在函数 "public: int __thiscall CUDTUnited::bind(int,unsigned int)" (?bind@CUDTUnited@@QAEHHI@Z) 中被引用
1>channel.obj : error LNK2001: 无法解析的外部符号 __imp__getsockname@12
1>api.obj : error LNK2019: 无法解析的外部符号 __imp__ntohs@4,该符号在函数 "private: void __thiscall CUDTUnited::updateMux(class CUDTSocket *,struct sockaddr const *,unsigned int const *)" (?updateMux@CUDTUnited@@AAEXPAVCUDTSocket@@PBUsockaddr@@PBI@Z) 中被引用
1>channel.obj : error LNK2019: 无法解析的外部符号 __imp__freeaddrinfo@4,该符号在函数 "public: void __thiscall CChannel::open(struct sockaddr const *)" (?open@CChannel@@QAEXPBUsockaddr@@@Z) 中被引用
1>channel.obj : error LNK2019: 无法解析的外部符号 __imp__getaddrinfo@16,该符号在函数 "public: void __thiscall CChannel::open(struct sockaddr const *)" (?open@CChannel@@QAEXPBUsockaddr@@@Z) 中被引用
1>channel.obj : error LNK2019: 无法解析的外部符号 __imp__bind@12,该符号在函数 "public: void __thiscall CChannel::open(struct sockaddr const *)" (?open@CChannel@@QAEXPBUsockaddr@@@Z) 中被引用
1>channel.obj : error LNK2019: 无法解析的外部符号 __imp__socket@12,该符号在函数 "public: void __thiscall CChannel::open(struct sockaddr const *)" (?open@CChannel@@QAEXPBUsockaddr@@@Z) 中被引用
1>channel.obj : error LNK2019: 无法解析的外部符号 __imp__setsockopt@20,该符号在函数 "private: void __thiscall CChannel::setUDPSockOpt(void)" (?setUDPSockOpt@CChannel@@AAEXXZ) 中被引用
1>channel.obj : error LNK2019: 无法解析的外部符号 __imp__closesocket@4,该符号在函数 "public: void __thiscall CChannel::close(void)const " (?close@CChannel@@QBEXXZ) 中被引用
1>channel.obj : error LNK2019: 无法解析的外部符号 __imp__getsockopt@20,该符号在函数 "public: int __thiscall CChannel::getSndBufSize(void)" (?getSndBufSize@CChannel@@QAEHXZ) 中被引用
1>channel.obj : error LNK2019: 无法解析的外部符号 __imp__getpeername@12,该符号在函数 "public: void __thiscall CChannel::getPeerAddr(struct sockaddr *)const " (?getPeerAddr@CChannel@@QBEXPAUsockaddr@@@Z) 中被引用
1>channel.obj : error LNK2019: 无法解析的外部符号 __imp__ntohl@4,该符号在函数 "public: int __thiscall CChannel::sendto(struct sockaddr const *,class CPacket &)const " (?sendto@CChannel@@QBEHPBUsockaddr@@AAVCPacket@@@Z) 中被引用
1>channel.obj : error LNK2019: 无法解析的外部符号 __imp__WSASendTo@36,该符号在函数 "public: int __thiscall CChannel::sendto(struct sockaddr const *,class CPacket &)const " (?sendto@CChannel@@QBEHPBUsockaddr@@AAVCPacket@@@Z) 中被引用
1>channel.obj : error LNK2019: 无法解析的外部符号 __imp__htonl@4,该符号在函数 "public: int __thiscall CChannel::sendto(struct sockaddr const *,class CPacket &)const " (?sendto@CChannel@@QBEHPBUsockaddr@@AAVCPacket@@@Z) 中被引用
1>channel.obj : error LNK2019: 无法解析的外部符号 __imp__WSARecvFrom@36,该符号在函数 "public: int __thiscall CChannel::recvfrom(struct sockaddr *,class CPacket &)const " (?recvfrom@CChannel@@QBEHPAUsockaddr@@AAVCPacket@@@Z) 中被引用
1>core.obj : error LNK2019: 无法解析的外部符号 __imp__getnameinfo@28,该符号在函数 "private: int __thiscall CUDT::listen(struct sockaddr *,class CPacket &)" (?listen@CUDT@@AAEHPAUsockaddr@@AAVCPacket@@@Z) 中被引用
1>epoll.obj : error LNK2019: 无法解析的外部符号 ___WSAFDIsSet@8,该符号在函数 "public: int __thiscall CEPoll::wait(int,class std::set<int,struct std::less<int>,class std::allocator<int> > *,class std::set<int,struct std::less<int>,class std::allocator<int> > *,__int64,class std::set<unsigned int,struct std::less<unsigned int>,class std::allocator<unsigned int> > *,class std::set<unsigned int,struct std::less<unsigned int>,class std::allocator<unsigned int> > *)" (?wait@CEPoll@@QAEHHPAV?$set@HU?$less@H@std@@V?$allocator@H@2@@std@@0_JPAV?$set@IU?$less@I@std@@V?$allocator@I@2@@3@2@Z) 中被引用
1>epoll.obj : error LNK2019: 无法解析的外部符号 _select@20,该符号在函数 "public: int __thiscall CEPoll::wait(int,class std::set<int,struct std::less<int>,class std::allocator<int> > *,class std::set<int,struct std::less<int>,class std::allocator<int> > *,__int64,class std::set<unsigned int,struct std::less<unsigned int>,class std::allocator<unsigned int> > *,class std::set<unsigned int,struct std::less<unsigned int>,class std::allocator<unsigned int> > *)" (?wait@CEPoll@@QAEHHPAV?$set@HU?$less@H@std@@V?$allocator@H@2@@std@@0_JPAV?$set@IU?$less@I@std@@V?$allocator@I@2@@3@2@Z) 中被引用
1>F:\C_TEST\test_udt\Debug\udt_appserver.exe : fatal error LNK1120: 20 个无法解析的外部命令
1>
1>生成失败。
1>
1>已用时间 00:00:01.05
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

 

然后将各个问题进行定位,再手动添加各个.h文件,发现就是治标不治本,最后终于找到解决方法:

#pragma comment(lib,"ws2_32.lib")

也就是在是编写的.cpp或者是.h文件的引用后添加上面那行就行了。
这句话的前面意思是静态加入一个lib文件


也就是库文件


ws2_32.lib文件,提供了对以下网络相关API的支持,若使用其中的API,则应该将ws2_32.lib加入工程(否则需要动态载入ws2_32.dll)。


这句话一般出现在网络编程中,需要使用网络API函数的时候,就必须使用这条语句加载ws2_32.lib库或者动态载入ws2_32.dll。

针对#pragma comment的具体使用方式请参考百度百科:#pragma comment

error LNK2019: 无法解析的外部符号

标签:

原文地址:http://www.cnblogs.com/djiankuo/p/5092341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!