1 包含目錄,包含libsmi文件夾下的lib文件夾和win文件夾,lib文件夾中包括libsmi庫的源文件。其中最主要的文件的頭文件是smi.h,也可以把smi.h文件拷貝到vc目錄的include文件夾。
注意事項:smi.h文件會與snmp++的頭文件smi.h衝突,其中一個需要包括絕對路徑。
2 包含靜態lib文件,編譯成功的lib文件拷貝到vc目錄的lib文件夾中。
編譯環境的配置
Debug版本
1 Use run-time libray一定要選擇Debug Multithreaded DLL這一選項,否則會發生error link 2005的編譯錯誤
2 包含lib文件一定要包含debug版本的靜態庫
Release版本
1 Use run-time library一定要選擇Multithreaded DLL,至於原因是什麼,以後慢慢研究了。
2 同樣包含lib文件一定要使用release版本的。
測試程序
#include<iostream>
using namespace std;
#include<smi.h>
void main()
{
smiInit(NULL);
SmiModule *smiModule;
SmiNode *smiNode;
SmiNodekind smiNodeKind;
SmiImport *smiImport;
//smiInit(NULL);
smiSetErrorLevel(2);
smiSetPath("H:\\mib\\rfc;H:\\mib\\h3c");
cout<<smiGetPath()<<endl;
//cout<<smiLoadModule("rfc1213")<<endl;
cout<<smiLoadModule("huawei-vlan")<<endl;
smiModule=smiGetFirstModule();
//這段代碼用來尋找imports的導入庫,增加代碼可以自動加載相關MIB文件
smiImport=smiGetFirstImport(smiModule);
//if(smiImport!=NULL)
//int i=0;
while(smiImport!=NULL)
{
//cout<<smiImport->module<<endl;
//cout<<i<<":"<<smiImport->name<<endl;
cout<<smiImport->module<<endl;
smiImport=smiGetNextImport(smiImport);
//i++;
}
smiNode=smiGetFirstNode(smiModule,SMI_NODEKIND_ANY);
cout<<smiNode->name<<endl;
while(1)
{
smiNode=smiGetNextNode(smiNode,SMI_NODEKIND_ANY);
if(smiNode==NULL)
break;
cout<<smiNode->name<<"\t\t\t"<<smiRenderOID(smiNode->oidlen,smiNode->oid,SMI_RENDER_NUMERIC)<<endl;
}
smiExit();
}
相關文件在http://download.csdn.net/detail/zhaopengxslc/6478483 下載