windows下编译使用Net-SNMP.doc_第1页
windows下编译使用Net-SNMP.doc_第2页
windows下编译使用Net-SNMP.doc_第3页
windows下编译使用Net-SNMP.doc_第4页
windows下编译使用Net-SNMP.doc_第5页
免费预览已结束,剩余18页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

说明:根据net-snmp-5.6中的“README.win32”摘录和翻译。转载请注明出处。email:net-snmp 在windows下用MSVC编译(一)net-snmp是一个开源项目,提供关于snmp的一些库和工具。下载网址:/projects/net-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、“This guide describes building with Microsoft Visual C+ 6.0 and higher, withthe gcc compiler from MinGW / MSYS, and with the gcc compiler from Cygwin.As developers build with other Win32 environments, their notes will be included here.”这个指南介绍了如何使用VC+6.0及更高版本以及gcc来build。2、If you are using Microsoft Visual Studio 6.0, you will have to install thePlatform SDK (PSDK) first.如果使用的是VC6.0,那么必须先安装PSDK3、If you are using any of the following environments, the PSDK download is notnecessary as the required parts of the PSDK are included: - Microsoft Visual Studio 2002 or later. - Cygwin. - MinGW.使用的是这些环境的话,无需安装PSDK4、There are two ways to build Net-SNMP using Microsoft Visual C+. The firstand easiest method is using Configure and nmake on the command line, and the second is using the Workspace files inside the interactive developmentenvironment.两种方式来用VC build Net-SNMP.第一种,也是最简单的方法,就是在命令行下使用Configure和nmake。第二种,就是IDE下使用workspace文件。4.1、To use nmake on the command line, the Configure script is run first to createthe various makefiles. Once these have been created, nmake is used to buildthe applications. Perl is required to use this method, as the Configurescript is written in Perl. ActiveState ActivePerl is available at: /Products/ActivePerl/为了在命令行下使用nmake,必须先运行Configure脚本来生成makefile。由于Configure脚本是用Perl写的,所以要先安装ActivePerl4.2、The make file system is based on and uses the directory structure of the projects contained in the Workspace files which are described below. It isrecommended that you read and understand how the workspaces are configuredeven if you will only be using the command line Configure / nmake system.make文件系统是基工程的目录结构的,建议先阅读和理解workspace是如何配置的。4.3、For building via the interactive development environment, there are the Win32workspaces win32.dsw and libdll.dsw. The last workspace allows to build a DLLversion of snmplib (netsnmp.dll).对于使用IDE的情况,有win32.dsw和libdll.dsw这两个文件。后者可以用来编译snmplb的DLL版本4.4、There is one core development library (libsnmp), together with a number of utility projects for the individual executable commands (snmpget, snmpwalk, etc.). All of these projects require the .lib created by the libsnmp project.有一个核心的开发库libsnmp,和一些用于各种可执行命令(如snmpget)的工程。所有的这些工程都需要libsnmp工程产生的.lib文件4.5、The agent requires the core library plus the other three library projects(libagent, libhelpers and netsnmpmibs) together with the main agentproject (snmpd).这个代理需要核心库加上其他三个库工程libagent,libhelpers和netsnmpmibs,和主代理工程snmpd4.6、The final application project is the trap handler snmptrapd. This alsorequires the agent libraries (libagent and netsnmpmibs) as well as thecore development library.最终的应用工程师处理trap的snmptrapped。这同样需要代理库libagent和netsnmpmibs及核心开发库。4.7、There is a Debug version and Release version for each subproject. This is sothe Debug and Release versions of an application can be built and testedseparately.对于每个子工程,都有一个debug版本和一个发行(Release)版本。所以,一个应用的debug版本和Release版本可以独立编译测试4.8、VC+ 6.0, 7.1, 8.0 (2005) and 9.0 (2008) have been tested. Building withearlier Microsoft compiler versions is no longer supported.6.0及以后版本已经测试过,更早的版本不再支持4.9、OpenSSL is required to support the encryption capabilities in SNMPv3,or SHA authentication.要支持SNMPv3的加密或SHA鉴定(SHA authentication)的话,需要OpenSSL4.10、Since the MSVC build environment does not natively use configure nor maketo generate the various pathnames that the programs require, the header files need to be manually modified when using the IDE, and an install script isprovided. When using the Perl Configure / nmake system, the header files areautomatically modified and require no manual editing.由于VC不在本地使用configure或make命令来生成程序需要的各种路径名,所以在使用IDE的时候需要手动修改头文件,有一个安装脚本可以使用(bat文件, win32install-net-snmp.bat)。如果诸位看官使用的是Perl的configure/nmake的话,头文件会自动修改,无需劳您大驾。4.11、The projects are arranged so that ALL of the usable products, the .exe files,are written to the win32bin directory. The win32lib directory is used only to build the the files in the win32bin directory. Once building is completed, there is no further use for the files in the win32lib directory.所有可用的产物(products),exe文件,都被写入了win2/bin目录。这个目录只是用于编译目录中的文件。一朝编译成,该目录不再有用。5、Debug Information-Note that VC+ 6.0 has options for debugging information - the Program Database. This option is set in the Project settings, C/C+ tab, General category, and is turned on by default during the conversion of the project files. This option is not for use with a library, as it embeds debug information into the library that references an external file that will not be available to the linking application. If you get an error message along the lines of debugging information not available in file vc60.pdb, make sure the library debug option is set to Program Database or /Zi.如果出现debugging information not available in file vc60.pdb,参考上述内容。net-snmp 在windows下用MSVC编译(二)(原创作品,转载注明出处)继续阅读README.win32* Microsoft Visual C+ - Workspace - Building*The win32.dsw and win32dll.dsw workspaces allow to build the agent and theapplications. Proceed as follows:1. Update the version stamp in win32net-snmpnet-snmp-config.h. The current version can be found in the Unix configure script (top level folder) by looking for the PACKAGE_VERSION variable.win32.dsw和win32dll.dsw文件使得可以编译代理和应用。按如下操作:1. 更新头文件(win32net-snmpnet-snmp-config.h)中的版本号。当前版本号可以在unix的configure脚本中找到2. If SNMPv3 encryption capabilities or SHA authentication is required, install the OpenSSL DLL and library file as described in the section Microsoft Visual C+ - Building with OpenSSL and then continue with step 2.如果需要v3的加密功能,则安装OpenSSL DLL和 Microsoft Visual C+ - Building with OpenSSL 中介绍的库文件。然后,继续。3. The default installation path is c:usr. This folder will contain all the binaries, MIB files, configuration files etc. To change the location, the win32net-snmpnet-snmp-config.h file needs to be modified by changing the INSTALL_BASE variable. Note: All paths in net-snmp-config.h use the / UNIX pathname delimiter. If a drive letter is not specified, the current drive letter is assumed. For example: #define INSTALL_BASE c:/usr. 缺省安装路径为c:usr 。这个文件将保护所有的二进制文件,MIB文件,配置文件等。要更改位置的话,则修改win32net-snmpnet-snmp-config.h 中的INSTALL_BASE 变量。注意:上述头文件中的路径都是使用了UNIX系统中的/4. When building DLLs instead of static libraries, *change* the following line which is located near the top of the file: /* #undef NETSNMP_USE_DLL */ *to* #define NETSNMP_USE_DLL 1如果编译DLLs而不是静态库的话,照上述方法更改。5. Build the agent and the applications a. Open win32.dsw (static build) or win32dll.dsw (dynamic build). b. Click Build-Batch Build. c. Select the projects and configurations you want to build. d. Click ReBuild All. e. When building is done, View the Output window, clip and save to a text file if there is some information to share.编译步骤:打开win32.dsw(静态编译) 或者win32dll.dsw(动态编译)点击Build-Batch Build. 选择希望编译的工程和配置点击ReBuild All编译完后,查看Output窗口,若有需要分享的信息,剪辑后保存为txt6. If the Perl modules are required, continue with the next section: Microsoft Visual C+ - Building the Perl SNMP modules. Otherwise, continue with the section: Microsoft Visual C+ - Installing如果需要Perl模块,则继续 Microsoft Visual C+ - Building the Perl SNMP modules这一节否则,继续 Microsoft Visual C+ Installing* Microsoft Visual C+ - Workspace - Installing*The install script win32install-net-snmp.bat should be run after abuild is successful. It copies the programs, MIB files, and developmentcomponents to an install directory named in the INSTALL_BASE variable.安装脚本 win32install-net-snmp.bat需要在build成功结束后再运行。它将程序(programs),MIB文件,和开发组件复制到一个INSTALL_BASE变量指定的路径。1. Complete the section Microsoft Visual C+ - Building. 完成Microsoft Visual C+ - Building这一小节。2. Open win32install-net-snmp.bat using a text editor. The INSTALL_BASE variable must match the INSTALL_BASE compile constant defined in win32net-snmpnet-snmp-config.h, using these rules:用记事本打开win32install-net-snmp.bat。其中的 INSTALL_BASE变量必须和头文件win32net-snmpnet-snmp-config.h中定义的一致。 a. All paths in install-net-snmp.bat use the DOS pathname delimiter. Example: set INSTALL_BASE=c:usr. 脚本中使用的为 b. All paths in net-snmp-config.h use the / UNIX pathname delimiter. If a drive letter is not specified, the current drive letter is assumed. Example: #define INSTALL_BASE c:/usr. Note: You may also modify install-net-snmp.bat in order to not install the linking libraries, or the header -snmp-config.h 中使用的是/3. Open a command prompt window.打开一个命令提示符窗口4. Cd to the base directory where this file README.win32 is located.进入到README.win32所在的根目录5. Run win32install-net-snmp.bat to install the programs. 运行win32install-net-snmp.bat # sample output from install-net-snmp.bat 一个输出样例如下: NOTE: Directory already exist messages are normal. If you are not building with OpenSSL, then DLL not found messages are normal. ”Directory already exist“这个消息的出现是正常的。如果没有build with的话,”DLL not found“也是正常的。 C:net-snmp-5.1.1 win32install-net-snmp Remember to run this script from the base of the source directory. Creating c:usr sub-directories A subdirectory or file c:usr already exists. A subdirectory or file c:usrbin already exists. A subdirectory or file c:usretcsnmp already exists. A subdirectory or file c:usrsharesnmpsnmpconf-data already exists A subdirectory or file c:usrsharesnmpsnmpconf-data snmp-data already exists. A subdirectory or file c:usrsharesnmpsnmpconf-data snmpd-data already exists. A subdirectory or file c:usrsharesnmpsnmpconf-data snmptrapd-data already exists. A subdirectory or file c:usrlib already exists. A subdirectory or file c:usrmibs already exists. A subdirectory or file c:usrinclude already exists. A subdirectory or file c:usrincludenet-snmp already exists . A subdirectory or file c:usrincludeucd-snmp already exists . Copying MIB files to c:usrmibs Copying compiled programs to c:usrbin Copying snmpconf files to c:usrsharesnmpsnmpconf- datasnmp-data Copying link libraries to c:usrlib Copying header files to c:usrinclude Deleting debugging files from c:usr Copying DLL files to c:usr The system cannot find the file specified. Done copying files to c:usr C:net-snmp-5.1.1 # END sample output from install-net-snmp.bat#输出样例结束6. Add the bin folder (c:usrbin in the above example) to your system path.将bin文件夹加到系统路径中7. Test the installation. For a simple test to see if Net-SNMP is working, open a _new_ command prompt window, and type: snmptranslate -IR -Td linkDown测试安装情况。例如打开命令提示符窗口,键入如下:snmptranslate -IR -Td linkDown8. If the folder that Net-SNMP was installed to is ever changed, modify the system environment variables or registry keys as explained in the Configuration_Overview.html file located in win32/dist/htmlhelp.如果Net-SNMP安装位置有变,那么修改系统的环境变量或者注册表,参考 Configuration_Overview.html,它位于win32/dist/htmlhelp.至此,编译告一段落了。看到一篇文章,各位看官可以对比着看看:一、准备工作 1、安装Microsoft Visual Studio 2005,其中Visual C+为必选组件 2、安装Active Perl解析器至C:usr目录下 该步骤必须执行,否则在后期执行配置操作时,会提示没有安装perl解析器的错误,从而无法自动配置。 二、编译NET-SNMP源文件(基于readme.win32中的Microsoft Visual C+ - Workspace - Building部分) 1、配置默认安装路径,打开net-snmp-5.1.3win32net-snmpnet-snmp-config.h,将第8行改为#define INSTALL_BASE C:/usr 在net-snmp-config.h文件中,所有的路径都是使用UNIX下的/符号,如果将其改为Windows下的符号的话,反而会在后期配置时出现路径错误。 2、在Visual Studio 2005中打开net-snmp-5.1.3win32win32.dsw,点击“全部都是”转换工作空间。 3、单击菜单栏的“生成”下的“配置管理器”,将活动解决方案配置从Debug改成release。此处也可以不修改,但是在后面的安装过程中,需要加入“-debug”参数。(后续内容以不修改为例)。 4、在右侧解决方案资源管理器中,依次对libagent、libhelpers、libnetsnmptrapd、snmplib、netsnmpmibs这五个项目单击鼠标右键,选择“重新生成”。 5、单击菜单栏的“生成”下的“生成解决方案”。 6、单击菜单栏的“生成”下的“配置管理器”,在“项目上下文中”color=去掉/color对libagent、libhelpers、libnetsnmptrapd、snmplib、netsnmpmibs这五个项目的选择,其余不变。 7、单击菜单栏的“生成”下的“重新生成”。 8、编译结束之后,单击菜单栏的“文件”下的“color=关闭解决方案/color”,退出。 三、安装NET-SNMP(基于readme.win32中的Microsoft Visual C+ - Workspace - Installing部分) 1、打开net-snmp-5.1.3win32install-net-snmp.bat,检查第12行是否为set INSTALL_BASE=c:usr,不是的话请改成这个。 2、打开命令提示符窗口,进入net-snmp-5.1.3win32目录下,运行 install-net-snmp.bat -debug 安装。 如果编译的时候将活动解决方案配置改成了release的话,直接运行install-net-snmp.bat即可。 3、拷贝net-snmp-5.1.3win32local*.bat文件至C:usrbin目录下。 该步骤本应该在执行批处理的时候自动执行,但实际上这些文件并没有被拷贝过去,所以我们必须手动进行,否则无法配置。 四、检查文件是否完整,在C:usrbin目录下应该存在下列22个文件 mib2c.bat、snmpconf.bat、traptoemail.bat、snmpconf、snmpbulkget.exe、 snmpbulkwalk.exe、snmpd.exe、snmpdelta.exe、snmpdf.exe、snmpget.exe、 snmpgetnext.exe、snmpnetstat.exe、snmpset.exe、snmpstatus.exe、 snmptable.exe、snmptest.exe、snmptranslate.exe、snmptrap.exe、snmptrapd.exe、 snmpusm.exe、snmpvacm.exe、snmpwalk.exe 五、配置NET-SNMP(基于readme.win32中的Configuring Net-SNMP部分) 1、打开C:usrbinsnmpconf.bat,检查第2行是否为set MYPERLPROGRAM=c:usrbinsnmpconf,不是的话请改成这个。 2、打开C:usrbinsnmpconf,查找所有/usr/local/并替换为C:/usr/。 该步骤必须执行,snmpconf中的文件路径采用的是UNIX下的/usr/local/,这里必须改为Windows下的C:/usr/,但/符号仍然保持UNIX下的/符号,不用改成windows下的符号,否则运行时会提示无法创建路径。 3、运行 snmpconf -i 4、选择 3: snmp.conf 5、选择 3: Textual mib parsing 6、选择 1: Specifies directories to be searched for mibs. 7、输入 c:usrsharesnmpmibs 8、输入 finished回车 finished回车 quit回车,正常退出。 9、将C:usrsharesnmp目录下的snmp.conf拷贝至C:usretcsnmp目录。 10、拷贝net-snmp-5.1.3win32EXAMPLE.conf.win32至C:usretcsnmp目录下,并改名snmpd.conf 11、打开刚刚拷贝的snmpd.conf,将第71行改为com2sec locallocalhostpublic 原文件中71行的COMMUNITY部分必须被改成public,COMMUNINTY只是个例子,不修改的话后期无法正常执行。 12、删除或者注释掉第72行。 理由与上一条相同,NETWORK/24也只是个例子。 六、运行NET-SNMP 1、打开一个命令提示符窗口,运行 snmpd -f -Le -d 2、提示如下则正确运行: NET-SNMP version 5.1.3 3、新开一个命令行窗口,运行 snmpget -c public -v 2c localhost system.sysUpTime.0 4、当前窗口提示如下: SNMPv2-MIB:sysUpTime.0 = Timeticks: (8279) 0:01:22.79 5、原命令行窗口提示如下: Received 41 bytes from 76 0000: 30 27 02 01 01 04 06 70 75 62 6C 69 63 A0 1A 020.public. SMM) 0016: 02 0F BC 02 01 00 02 01 00 30 0E 30 0C 06 08 2B.0.0.+ 0032: 06 01 02 01 01 03 00 05 00. Received SNMP packet(s) from GET message - SNMPv2-MIB:sysUpTime.0 Sending 43 bytes to 0000: 30 29 02 01 01 04 06 70 75 62 6C 69 63 A2 1C 020).public. 0016: 02 0F BC 02 01 00 02 01 00 30 10 30 0E 06 08 2B.0.0. 0032: 06 01 02 01 01 03 00 43 02 20 57. 原文 /blog.php?do-showone-type-blog-itemid-2118.html Microsoft Visual C+ - Building your own applications with snmplib* Microsoft Visual C+ - Building your own applications with snmplib*Linking in an snmplib built to use the Multithreaded DLL runtime library to an application configured for the Debug Multithreaded DLL runtime library results in a link error along the lines of defaultlib MSVCRT conflicts with use of other libs. If you receive a similar message, check that theprojects settings between library and application match up. 链接错误:defaultlib MSVCRT conflicts with use of other libs 这种情况下,核实一下,library 和application间的projects settings是匹配的。To successfully build your existing project with Net-SNMP libraries,change the project settings FOR YOUR APPLICATION ONLY as follows:要成功将你的现有工程和Net-SNMP库build,需要将project settings FOR YOUR APPLICATION ONLY进行如下更改:1. In the Link section, Select Additional Libraries. Add netsnmp.lib for Release version. Add netsnmp_d.lib for Debug version.在Link中,选择Additional Libraries.添加netsnmp.lib( for Release version)或 netsnmp_d.lib( for Debug version.) 2. Remove all references to these libraries: libsnmp*.lib msvcrt*.lib libc*.lib oldnames.lib移去所有对这三个库的引用:libsnmp*.lib msvcrt*.lib libc*.lib oldnames.lib 3. In the C+ section, Select Code Generation. For Release, select /MD or MultiThreaded DLL. For Debug, select /MDd or Debug MultiThreaded DLL.在C+区(?

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论