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 下载