下面就是SNMP++的使用了,以一个例子来说明,源代码如下:
#include
#include
void main()
{
}
但是它在VC6中的编译还是有一些技巧的,我按顺序说一下:
(1)在VC中新建一个Win32
Application的程序,命名为Cip,如图9所示
图9
(2)新建一个C++源文件,名为Cip,如图10所示
(3)把源代码贴进去
(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所示
这样执行“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所示
执行“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所示
图13
有两处改动,一是添加了一条/nodefaultlib:”libcmtd”,二是把/subsystem:window改成了/subsystem:console。
程序最后的运行结果,如图所示
图14
以上就是整个的SNMP++在VC6下的编译和使用过程,写的很罗嗦,但主要是我在学习的过程中遇到很多困难,但是解决问题的过程也是能力提高的过程,所以记录下来与大家分享。


加载中…