发博文
正文 字体大小:

SNMP++在VC6下的编辑和使用(三)

(2007-03-18 23:19:35)

下面就是SNMP++的使用了,以一个例子来说明,源代码如下:
#include
#include
void main()
{

 IpAddress ip("127.0.0.1");
 cout<<"ip address is:"<
 UdpAddress udp("127.0.0.1:8888");
 cout<<"udp address is:"<
 cout<<"udp address port is:"<<<ENDL;
 udp="127.0.0.1";
 udp.set_port(9999);
 cout<
 ip="258.0.0.1";
  if(!ip.valid())
   cout<<"bad ip:258.0.0.1"<
  else
   cout<<"good ip:258.0.0.1"<
  ip="255.0.0.1";
 if(!ip.valid())
  cout<<"error ip:255.0.0.1"<
 else
  cout<<"good ip:255.0.0.1"<
 ip="0.0.0.0";
 if(!ip.valid())
  cout<<"error ip:0.0.0.0"<
 else
  cout<<"good ip:0.0.0.0"<
 ip="255.255.255.255";
  if(!ip.valid())
   cout<<"error ip:255.255.255.255"<
  else
   cout<<"good ip:255.255.255.255"<< FONT>

}
但是它在VC6中的编译还是有一些技巧的,我按顺序说一下:
(1)在VC中新建一个Win32 Application的程序,命名为Cip,如图9所示

SNMP++在VC6下的编辑和使用(三)

图9
(2)新建一个C++源文件,名为Cip,如图10所示

SNMP++在VC6下的编辑和使用(三)

(3)把源代码贴进去

SNMP++在VC6下的编辑和使用(三)

(4)试编译一次
会出一大堆这些的错:
--------------------Configuration: Cip - Win32 Debug--------------------
Compiling...
Cip.cpp
Linking...
Cip.obj : error LNK2001: unresolved external symbol "public: class IpAddress & __thiscall IpAddress::operator=(char const *)" (??4IpAddress@@QAEAAV0@PBD@Z)
Cip.obj : error LNK2001: unresolved external symbol "public: void __thiscall UdpAddress::set_port(unsigned short)" (?set_port@UdpAddress@@QAEXG@Z)
Cip.obj : error LNK2001: unresolved external symbol "public: class UdpAddress & __thiscall UdpAddress::operator=(char const *)" (??4UdpAddress@@QAEAAV0@PBD@Z)
Cip.obj : error LNK2001: unresolved external symbol "public: unsigned short __thiscall UdpAddress::get_port(void)const " (?get_port@UdpAddress@@QBEGXZ)
Cip.obj : error LNK2001: unresolved external symbol "public: __thiscall UdpAddress::UdpAddress(char const *)" (??0UdpAddress@@QAE@PBD@Z)
Cip.obj : error LNK2001: unresolved external symbol "public: __thiscall IpAddress::IpAddress(char const *)" (??0IpAddress@@QAE@PBD@Z)
Cip.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall IpAddress::map_to_ipv6(void)" (?map_to_ipv6@IpAddress@@UAEHXZ)
Cip.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall IpAddress::format_output(void)const " (?format_output@IpAddress@@MBEXXZ)
Cip.obj : error LNK2001: unresolved external symbol "protected: virtual bool __thiscall IpAddress::parse_address(char const *)" (?parse_address@IpAddress@@MAE_NPBD@Z)
Cip.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall IpAddress::clear(void)" (?clear@IpAddress@@UAEXXZ)
Cip.obj : error LNK2001: unresolved external symbol "public: virtual class SnmpSyntax & __thiscall IpAddress::operator=(class SnmpSyntax const &)" (??4IpAddress@@UAEAAVSnmpSyntax@@ABV1@@Z)
Cip.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall Address::clear(void)" (?clear@Address@@MAEXXZ)
Cip.obj : error LNK2001: unresolved external symbol "public: __thiscall IpAddress::IpAddress(class IpAddress const &)" (??0IpAddress@@QAE@ABV0@@Z)
Cip.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall UdpAddress::map_to_ipv6(void)" (?map_to_ipv6@UdpAddress@@UAEHXZ)
Cip.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall UdpAddress::format_output(void)const " (?format_output@UdpAddress@@MBEXXZ)
Cip.obj : error LNK2001: unresolved external symbol "protected: virtual bool __thiscall UdpAddress::parse_address(char const *)" (?parse_address@UdpAddress@@MAE_NPBD@Z)
Cip.obj : error LNK2001: unresolved external symbol "public: virtual class SnmpSyntax & __thiscall UdpAddress::operator=(class SnmpSyntax const &)" (??4UdpAddress@@UAEAAVSnmpSyntax@@ABV1@@Z)
Cip.obj : error LNK2001: unresolved external symbol "public: __thiscall UdpAddress::UdpAddress(class UdpAddress const &)" (??0UdpAddress@@QAE@ABV0@@Z)
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/Cip.exe : fatal error LNK1120: 19 unresolved externals
Error executing link.exe.

Cip.exe - 20 error(s), 0 warning(s)
其实是因为没有把snmp_pp.lib包括进去,把它加进去即可,如图11所示

SNMP++在VC6下的编辑和使用(三)

这样执行“Rebuild All”命令后,只有9个错误了,如下所示:
Deleting intermediate files and output files for project 'Cip - Win32 Debug'.
--------------------Configuration: Cip - Win32 Debug--------------------
Compiling...
Cip.cpp
Linking...
LINK : warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs; use /NODEFAULTLIB:library
snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _WSAGetLastError@0
snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _inet_ntoa@4
snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _gethostbyname@4
snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _gethostbyaddr@12
snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _inet_addr@4
snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _htons@4
snmp_pp.lib(address.obj) : error LNK2001: unresolved external symbol _ntohs@4
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/Cip.exe : fatal error LNK1120: 8 unresolved externals
Error executing link.exe.

Cip.exe - 9 error(s), 1 warning(s)
我们再一一解决,把WS2_32.LIB文件包括进来,如图12所示

SNMP++在VC6下的编辑和使用(三)

执行“Rebuild All”命令后,只有2个错误了,如下所示
Deleting intermediate files and output files for project 'Cip - Win32 Debug'.
--------------------Configuration: Cip - Win32 Debug--------------------
Compiling...
Cip.cpp
Linking...
LINK : warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs; use /NODEFAULTLIB:library
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/Cip.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Cip.exe - 2 error(s), 1 warning(s)
再改一下,如图13所示

SNMP++在VC6下的编辑和使用(三)

图13
有两处改动,一是添加了一条/nodefaultlib:”libcmtd”,二是把/subsystem:window改成了/subsystem:console。
程序最后的运行结果,如图所示

SNMP++在VC6下的编辑和使用(三)

图14
以上就是整个的SNMP++在VC6下的编译和使用过程,写的很罗嗦,但主要是我在学习的过程中遇到很多困难,但是解决问题的过程也是能力提高的过程,所以记录下来与大家分享。

阅读 评论 收藏 转载 打印举报
  • 评论加载中,请稍候...

       

    验证码: 请点击后输入验证码 收听验证码

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 不良信息反馈 电话:4006900000 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有