VS2017編譯SNMP++步驟記錄


 1、下載地址:https://www.agentpp.com/download.html

三個都下

 

2、新建解決方案 TestSnmp

  

 

 

3、下載后解壓到解決方案文件夾(注意,解壓后的 snmp++的版本號要去掉,另外 vs2013改成 vs2017)

 

 

這個 include 目錄里頭有幾個 .h 文件,需要替換掉 snmp++ 里頭對應的文件 (其中  config.h 是新增加的)

 

4、打開vs2017文件夾下的 README.win32 看一下步驟。

README WIN32
============

The Visual Studio 2013 project files require that the 
libdes, SNMP++, AGENT++, and/or AgentX++ sources
are extracted in the same directory as the Visual Studio
project files. The directory structure should then look
like (note: there must not be any version numbers in the
directory names):

common-root-dir
 |-- libdes
 |-- snmp++
 |-- agent++
 |-- agentx++
 |-- vs2013

Make sure, that you delete the file config_snmp_pp.h from
the snmp++\include\snmp_pp directory. Otherwise, the linked
programs crash on execution, because the different projects
might have used different versions of the config_snmp_pp.h
file.

The file with the right (default) settings for the WIN32 platform
is located in vs2013\SNMP++\include\snmp_pp and included from
there by the VS project files.

To build the libraries, use this order:

1. libdes (or openssh)
2. SNMP++
3. AGENT++
4. AgentX++

這里提示我們要用


vs2013\SNMP++\include\snmp_pp\config_snmp_pp.h    來替換掉   snmp++\include\snmp_pp\config_snmp_pp.h

我們可以先不刪,直接將  snmp++\include\snmp_pp\config_snmp_pp.h 重命名一下為 delete_config_snmp_pp.h 即可

 

5、打開 vs2017文件夾刪掉(AGENT++,AgentX++)兩個項目,我們這里用不着。

6、在 TestSnmp解決方案上點右鍵添加現有項目,將 libdes 和 snmp++ 添加進來

路徑分別為: 

vs2017\libdes\libdes\libdes.vcxproj

vs2017\SNMP++\SNMP++\SNMP++.vcxproj

7、如果您的 windows sdk 版本不一致,需要將兩個項目都進行“重定向項目”操作

  

 

 

項目重定向后其后的(VS Studio 2013)會消失

8、嘗試一下生成 libdes(直接成功了)

9、嘗試一下生成 SNMP++(出錯了,提示找不到 libsnmp.h

    

   我們在整個項目文件夾里搜索一下 libsnmp.h 文件名,發現它在\TestSnmp\snmp++文件夾里,下面將這個路徑添加到 include 路徑里。

  在VS2017里的SNMP++ 項目上點右鍵 -> 屬性

 

發現它這個路徑配置有問題(是用的絕對路徑)我們改一下改成【$(SolutionDir)】,然后把【$(SolutionDir)snmp++】也加進去

 

 

順手把 C/C++ 里的附加目錄也修改正確

它原來是【$(SolutionDir)\..\..\libdes】改成【$(SolutionDir)libdes】

 

10、再次編譯snmp++項目(這次它提示無法打開包括文件: “unistd.h”)

繼續在解決方案文件夾里搜一下看看,發現它在 $(SolutionDir)vs2017\SNMP++\include

 

將【$(SolutionDir)vs2017\SNMP++\include】加入 c/c++目錄

11、再一次嘗試編譯 SNMP++項目

看着錯誤挺多,其實就只有三個主要錯誤【上頭提示的什么 if 非法 else 之類的,想來作者不會有這么低級的錯誤,我們不要隨便去懷疑,先把這三個明確的問題解決了說不定就跟着解決了】
1、pp_int64 標識符錯誤

2、inet_ntop 重定義

3、'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings SNMP++ 

解決辦法:

1、在這里第一個錯誤,我們搜了一下解決方案文件內容,發現確實只有這一個地方用了 pp_int64,我們換成 int64_t 試試,發現是可以的,改了有啥后果,暫時不知道,后面我們再觀察吧。

2、inet_ntop 重定義這個,我們定位到文件【IPv6Utility.h】將其屏蔽【//const char * inet_ntop(int af, const void *src, char *dst, size_t size);】

3、這個提示是 inet_ntoa 過期了,可以用 inet_ntop 或 InetNtop 代替,為了避免修改源碼,我們按后面的提示,在工程屬性里加 【_WINSOCK_DEPRECATED_NO_WARNINGS 】預編譯項

 

12、再一次編譯 SNMP++項目,恭喜【========== 生成: 成功 1 個,失敗 0 個,最新 0 個,跳過 0 個 ==========】

13、添加測試項目【vs2017\SNMP++\snmpWalk\snmpWalk.vcxproj】,並設置為啟動項,修改VC++目錄

14、Ctrl + F5 運行

看來我們需要去命令行下帶參數運行

 

15、開始 -> 運行 -> cmd 打開命令行

  

搞定,收工!!!!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM