error LNK2019: 无法解析的外部符号
2015-12-31 17:33
766 查看
最近在尝试用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
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
相关文章推荐
- Global Azure SQL Server副本功能配置介绍
- Android对Bitmap的内存优化方案总结
- 2015:充实
- Merge Sort(归并排序)的JAVA与Python实现
- Android声音录制和播放
- MATLAB复杂网络工具箱——matgraph基本操作总结
- Struts2 标签库讲解
- Cygwin下vi和vim方向键和Backspace不好用的问题(转)
- WordPress中登陆后关闭登陆页面及设置用户不可见栏目
- 【Unix编程】文件处理函数
- HDU 5592 ZYB's Premutation
- Redis 主从复制 原理与用法
- JVM学习笔记(四)------内存调优
- struts2常用标签详解
- android开发水波纹效果实现
- RabbitMQ 基础使用
- Android下拉框的实现
- 我们的大数据时代
- JVM学习笔记(二)------Java代码编译和执行的整个过程
- JVM学习笔记(三)------内存管理和垃圾回收