windows下编译使用NetSNMP.docx
- 文档编号:11079046
- 上传时间:2023-05-29
- 格式:DOCX
- 页数:27
- 大小:31.19KB
windows下编译使用NetSNMP.docx
《windows下编译使用NetSNMP.docx》由会员分享,可在线阅读,更多相关《windows下编译使用NetSNMP.docx(27页珍藏版)》请在冰点文库上搜索。
windows下编译使用NetSNMP
说明:
根据net-snmp-5.6中的“README.win32”摘录和翻译。
转载请注明出处。
email:
wulinshuxue@
net-snmp在windows下用MSVC编译
(一)
net-snmp是一个开源项目,提供关于snmp的一些库和工具。
下载网址:
目前的最新版本是5.6。
如果想简单地安装一下的话,可以下载x86的exe版本,一般最新版的程序还没有发布exe版本。
目前最新的exe版本为net-snmp-5.5.0-1.x86.exe。
在网上搜了一下,大多是在linux下的编译过程,windows下的情况比较少,另外,一些注意事项也很少。
在下载了net-snmp-5.6后,看到里面那么多的文件,觉得很晕。
我猜里面需要先读的文件大概是“win32.readme”,这个文件是在win32环境下编译使用net-snmp的说明文件。
用记事本打开后,估计超长的篇幅要让不少人崩溃。
不过没事,这是分小节写的,每小节有内容说明,条理很清晰。
摘录了一些说明,并作了大致的翻译,如下:
1、“ThisguidedescribesbuildingwithMicrosoftVisualC++6.0andhigher,with
thegcccompilerfromMinGW/MSYS,andwiththegcccompilerfromCygwin.
AsdevelopersbuildwithotherWin32environments,theirnoteswillbe
includedhere.”
这个指南介绍了如何使用VC++6.0及更高版本以及gcc来build。
2、IfyouareusingMicrosoftVisualStudio6.0,youwillhavetoinstallthe
PlatformSDK(PSDK)first.
如果使用的是VC6.0,那么必须先安装PSDK
3、Ifyouareusinganyofthefollowingenvironments,thePSDKdownloadisnot
necessaryastherequiredpartsofthePSDKareincluded:
-MicrosoftVisualStudio2002orlater.
-Cygwin.
-MinGW.
使用的是这些环境的话,无需安装PSDK
4、TherearetwowaystobuildNet-SNMPusingMicrosoftVisualC++. Thefirst
andeasiestmethodisusingConfigureandnmakeonthecommandline,andthe
secondisusingtheWorkspacefilesinsidetheinteractivedevelopment
environment.
两种方式来用VCbuildNet-SNMP.
第一种,也是最简单的方法,就是在命令行下使用Configure和nmake。
第二种,就是IDE下使用workspace文件。
4.1、Tousenmakeonthecommandline,theConfigurescriptisrunfirsttocreate
thevariousmakefiles. Oncethesehavebeencreated,nmakeisusedtobuild
theapplications. Perlisrequiredtousethismethod,astheConfigure
scriptiswritteninPerl. ActiveStateActivePerlisavailableat:
为了在命令行下使用nmake,必须先运行Configure脚本来生成makefile。
由于Configure脚本是
用Perl写的,所以要先安装ActivePerl
4.2、Themakefilesystemisbasedonandusesthedirectorystructureofthe
projectscontainedintheWorkspacefileswhicharedescribedbelow. Itis
recommendedthatyoureadandunderstandhowtheworkspacesareconfigured
evenifyouwillonlybeusingthecommandlineConfigure/nmakesystem.
make文件系统是基工程的目录结构的,建议先阅读和理解workspace是如何配置的。
4.3、Forbuildingviatheinteractivedevelopmentenvironment,therearetheWin32
workspaceswin32.dswandlibdll.dsw.ThelastworkspaceallowstobuildaDLL
versionofsnmplib(netsnmp.dll).
对于使用IDE的情况,有win32.dsw和libdll.dsw这两个文件。
后者可以用来编译snmplb的DLL版本
4.4、Thereisonecoredevelopmentlibrary('libsnmp'),togetherwithanumber
ofutilityprojectsfortheindividualexecutablecommands('snmpget',
'snmpwalk',etc...). Alloftheseprojectsrequirethe.libcreatedby
thelibsnmpproject.
有一个核心的开发库——libsnmp,和一些用于各种可执行命令(如snmpget)的工程。
所有的这些工程都需要libsnmp工程产生的.lib文件
4.5、Theagentrequiresthecorelibraryplustheotherthreelibraryprojects
('libagent',libhelpers'and'netsnmpmibs')togetherwiththemainagent
project('snmpd').
这个代理需要核心库加上其他三个库工程——libagent,libhelpers和netsnmpmibs,和
主代理工程——snmpd
4.6、Thefinalapplicationprojectisthetraphandler'snmptrapd'. Thisalso
requirestheagentlibraries('libagent'and'netsnmpmibs')aswellasthe
coredevelopmentlibrary.
最终的应用工程师处理trap的snmptrapped。
这同样需要代理库——libagent和netsnmpmibs
及核心开发库。
4.7、ThereisaDebugversionandReleaseversionforeachsubproject. Thisisso
theDebugandReleaseversionsofanapplicationcanbebuiltandtested
separately.
对于每个子工程,都有一个debug版本和一个发行(Release)版本。
所以,一个应用的debug版本和Release版本可以独立编译测试
4.8、VC++6.0,7.1,8.0(2005)and9.0(2008)havebeentested. Buildingwith
earlierMicrosoftcompilerversionsisnolongersupported.
6.0及以后版本已经测试过,更早的版本不再支持
4.9、OpenSSLisrequiredtosupporttheencryptioncapabilitiesinSNMPv3,
orSHAauthentication.
要支持SNMPv3的加密或SHA鉴定(SHAauthentication)的话,需要OpenSSL
4.10、SincetheMSVCbuildenvironmentdoesnotnativelyuse"configure"nor"make"
togeneratethevariouspathnamesthattheprogramsrequire,theheaderfiles
needtobemanuallymodifiedwhenusingtheIDE,andaninstallscriptis
provided. WhenusingthePerlConfigure/nmakesystem,theheaderfilesare
automaticallymodifiedandrequirenomanualediting.
由于VC不在本地使用configure或make命令来生成程序需要的各种路径名,所以在
使用IDE的时候需要手动修改头文件,有一个安装脚本可以使用(bat文件,"win32\install-net-snmp.bat")。
如果诸位看官使用的是Perl的configure/nmake的话,头文件会自动修改,无需劳您大驾。
4.11、TheprojectsarearrangedsothatALLoftheusableproducts,the.exefiles,
arewrittentothewin32\bindirectory. Thewin32\libdirectoryisusedonly
tobuildthethefilesinthewin32\bindirectory. Oncebuildingis
completed,thereisnofurtheruseforthefilesinthewin32\libdirectory.
所有可用的产物(products),exe文件,都被写入了win2/bin目录。
这个目录只是用于编译
目录中的文件。
一朝编译成,该目录不再有用。
5、DebugInformation
-----------------
NotethatVC++6.0hasoptionsfordebugginginformation-the'Program
Database'. ThisoptionissetintheProjectsettings,C/C++tab,'General'
category,andisturnedonbydefaultduringtheconversionoftheproject
files.Thisoptionisnotforusewithalibrary,asitembedsdebug
informationintothelibrarythatreferencesanexternalfilethatwill
notbeavailabletothelinkingapplication.Ifyougetanerrormessage
alongthelinesof'debugginginformationnotavailableinfilevc60.pdb,
makesurethelibrarydebugoptionissetto'ProgramDatabase'or"/Zi".
如果出现'debugginginformationnotavailableinfilevc60.pdb',参考上述内容。
net-snmp在windows下用MSVC编译
(二)
(原创作品,转载注明出处)
继续阅读README.win32
***************************************************************************
*
*MicrosoftVisualC++-Workspace-Building
*
***************************************************************************
Thewin32.dswandwin32dll.dswworkspacesallowtobuildtheagentandthe
applications.Proceedasfollows:
1.Updatetheversionstampinwin32\net-snmp\net-snmp-config.h. Thecurrent
versioncanbefoundintheUnixconfigurescript(toplevelfolder)by
lookingforthePACKAGE_VERSIONvariable.
win32.dsw和win32dll.dsw文件使得可以编译代理和应用。
按如下操作:
1.更新头文件(win32\net-snmp\net-snmp-config.h)中的版本号。
当前版本号可以在
unix的configure脚本中找到
2.IfSNMPv3encryptioncapabilitiesorSHAauthenticationisrequired,
installtheOpenSSLDLLandlibraryfileasdescribedinthesection
'MicrosoftVisualC++-BuildingwithOpenSSL"andthencontinuewith
step2.
如果需要v3的加密功能,则安装OpenSSLDLL和 'MicrosoftVisualC++-BuildingwithOpenSSL"
中介绍的库文件。
然后,继续。
3.Thedefaultinstallationpathisc:
\usr. Thisfolderwillcontainall
thebinaries,MIBfiles,configurationfilesetc. Tochangethelocation,
thewin32\net-snmp\net-snmp-config.hfileneedstobemodifiedbychanging
theINSTALL_BASEvariable.
Note:
Allpathsinnet-snmp-config.husethe"/"UNIXpathnamedelimiter.
Ifadriveletterisnotspecified,thecurrentdriveletterisassumed.
Forexample:
#defineINSTALL_BASE"c:
/usr".
缺省安装路径为c:
\usr。
这个文件将保护所有的二进制文件,MIB文件,配置文件等。
要更改位置的话,则修改win32\net-snmp\net-snmp-config.h中的INSTALL_BASE变量。
注意:
上述头文件中的路径都是使用了UNIX系统中的"/"
4. WhenbuildingDLLsinsteadofstaticlibraries,*change*thefollowing
linewhichislocatednearthetopofthefile:
/*#undefNETSNMP_USE_DLL*/
*to*
#defineNETSNMP_USE_DLL1
如果编译DLLs而不是静态库的话,照上述方法更改。
5.Buildtheagentandtheapplications
a.Openwin32.dsw(staticbuild)orwin32dll.dsw(dynamicbuild).
b.Click"Build->BatchBuild..."
c.Selecttheprojectsandconfigurationsyouwanttobuild.
d.Click"ReBuildAll".
e.Whenbuildingisdone,ViewtheOutputwindow,clipand
savetoatextfileifthereissomeinformationtoshare.
编译步骤:
打开win32.dsw(静态编译)或者win32dll.dsw(动态编译)
点击"Build->BatchBuild..."
选择希望编译的工程和配置
点击"ReBuildAll"
编译完后,查看Output窗口,若有需要分享的信息,剪辑后保存为txt
6. IfthePerlmodulesarerequired,continuewiththenextsection:
'MicrosoftVisualC++-BuildingthePerlSNMPmodules'.
Otherwise,continuewiththesection:
'MicrosoftVisualC++-Installing'
如果需要Perl模块,则继续 'MicrosoftVisualC++-BuildingthePerlSNMPmodules'这
一节.否则,继续'MicrosoftVisualC++Installing'
***************************************************************************
*
*MicrosoftVisualC++-Workspace-Installing
*
***************************************************************************
Theinstallscript"win32\install-net-snmp.bat"shouldberunaftera
buildissuccessful. Itcopiestheprograms,MIBfiles,anddevelopment
componentstoaninstalldirectorynamedintheINSTALL_BASEvariable.
安装脚本"win32\install-net-snmp.bat"需要在build成功结束后再运行。
它将程序(programs),MIB文件,和开发组件复制到一个INSTALL_BASE变量
指定的路径。
1. Completethesection'MicrosoftVisualC++-Building'.
完成MicrosoftVisualC++-Building'这一小节。
2. Openwin32\install-net-snmp.batusingatexteditor.
TheINSTALL_BASEvariablemustmatchtheINSTALL_BASEcompileconstant
definedin"win32\net-snmp\net-snmp-config.h",usingtheserules:
用记事本打开win32\install-net-snmp.bat 。
其中的INSTALL_BASE变量必须和头文件
"win32\net-snmp\net-snmp-config.h"中定义的一致。
a. Allpathsininstall-net-snmp.batusethe"\"DOSpathnamedelimiter.
Example:
setINSTALL_BASE="c:
\usr".
脚本中使用的为"\"
b. Allpathsinnet-snmp-config.husethe"/"UNIXpathnamedelimiter.
Ifadriveletterisnotspecified,thecurrentdriveletteris
assumed.
Example:
#defineINSTALL_BASE"c:
/usr".
Note:
Youmayalsomodify"install-net-snmp.bat"inordertonotinstall
thelinkinglibraries,ortheheaderfiles.
net-snmp-config.h中使用的是"/"
3. Openacommandpromptwindow.
打开一个命令提示符窗口
4. CdtothebasedirectorywherethisfileREADME.win32islocated.
进入到README.win32所在的根目录
5.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- windows 编译 使用 NetSNMP