error lnk1120 一个无法解析的外部错误 error LNK2001: 无法解析的外部符号 __iob
用c++编译一个snmp获取trap的程序,想把它从控制台改为win32的怎么搞啊?完全不会啊源代码在这,我改了下出现这个错误,求指教啊!!//0502.cpp:定义控制...
用c++编译一个snmp获取trap的程序,想把它从控制台改为win32的怎么搞啊?
完全不会啊
源代码在这,我改了下出现这个错误,求指教啊!!
// 0502.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "afx.h"
#include"snmp_pp.h"
#include"cstringt.h"
#include<iostream>
using namespace std;
#pragma comment(lib,"ws2_32.lib")
//#pragma comment(lib,"snmp_pp_debug.lib")
#pragma comment(lib,"snmp_pp.lib")
void callback( int reason, Snmp *snmp, Pdu &pdu, SnmpTarget &target, void *cd)
{
Vb nextVb;
int pdu_error;
GenAddress addr;
target.get_address(addr);
UdpAddress from(addr);
CTime time=CTime::GetCurrentTime();
wcout<<"Time:"<<(LPCTSTR)time.Format("%Y-%m-%d %H:%M:%S")<<endl;
cout << "reason: " << reason << endl
<< "msg: " << snmp->error_msg(reason) << endl
<< "from: " << from.get_printable() << endl;
pdu_error = pdu.get_error_status();
if (pdu_error){
cout << "Response contains error: "
<< snmp->error_msg(pdu_error)<< endl;
}
Oid id;
pdu.get_notify_id(id);
cout << "ID: " << id.get_printable() << endl;
cout << "Type:" << pdu.get_type() << endl;
for (int i=0; i<pdu.get_vb_count(); i++)
{
pdu.get_vb(nextVb, i);
cout << "Oid: " << nextVb.get_printable_oid() << endl
<< "Val: " << nextVb.get_printable_value() << endl;
}
if (pdu.get_type() == sNMP_PDU_INFORM) {
cout << "pdu type: " << pdu.get_type() << endl;
cout << "sending response to inform: " << endl;
nextVb.set_value("This is the response.");
pdu.set_vb(nextVb, 0);
snmp->response(pdu, target);
}
cout << endl;
}
void main(int argc, char **argv)
{
int trap_port;
if (argc < 2)
trap_port = 162; // no need to be root
else
trap_port = atoi(argv[1]);
//----------[ create a SNMP++ session ]-----------------------------------
int status;
Snmp::socket_startup(); // Initialize socket subsystem
Snmp snmp(status); // check construction status
if ( status != SNMP_CLASS_SUCCESS)
{
cout << "SNMP++ Session Create Fail, " << snmp.error_msg(status) << "\n";
}
OidCollection oidc;
TargetCollection targetc;
cout << "Trying to register for traps on port " << trap_port << "." << endl;
snmp.notify_set_listen_port(trap_port);
status = snmp.notify_register(oidc, targetc, callback, NULL);
if (status != SNMP_CLASS_SUCCESS)
{
cout << "Error register for notify (" << status << "): "
<< snmp.error_msg(status) << endl;
exit(1);
}
else
cout << "Waiting for traps/informs..." << endl;
snmp.start_poll_thread(1000);
cout << "press return to stop\n";
getc(stdin);
snmp.stop_poll_thread();
Snmp::socket_cleanup(); // Shut down socket subsystem
} 展开
完全不会啊
源代码在这,我改了下出现这个错误,求指教啊!!
// 0502.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "afx.h"
#include"snmp_pp.h"
#include"cstringt.h"
#include<iostream>
using namespace std;
#pragma comment(lib,"ws2_32.lib")
//#pragma comment(lib,"snmp_pp_debug.lib")
#pragma comment(lib,"snmp_pp.lib")
void callback( int reason, Snmp *snmp, Pdu &pdu, SnmpTarget &target, void *cd)
{
Vb nextVb;
int pdu_error;
GenAddress addr;
target.get_address(addr);
UdpAddress from(addr);
CTime time=CTime::GetCurrentTime();
wcout<<"Time:"<<(LPCTSTR)time.Format("%Y-%m-%d %H:%M:%S")<<endl;
cout << "reason: " << reason << endl
<< "msg: " << snmp->error_msg(reason) << endl
<< "from: " << from.get_printable() << endl;
pdu_error = pdu.get_error_status();
if (pdu_error){
cout << "Response contains error: "
<< snmp->error_msg(pdu_error)<< endl;
}
Oid id;
pdu.get_notify_id(id);
cout << "ID: " << id.get_printable() << endl;
cout << "Type:" << pdu.get_type() << endl;
for (int i=0; i<pdu.get_vb_count(); i++)
{
pdu.get_vb(nextVb, i);
cout << "Oid: " << nextVb.get_printable_oid() << endl
<< "Val: " << nextVb.get_printable_value() << endl;
}
if (pdu.get_type() == sNMP_PDU_INFORM) {
cout << "pdu type: " << pdu.get_type() << endl;
cout << "sending response to inform: " << endl;
nextVb.set_value("This is the response.");
pdu.set_vb(nextVb, 0);
snmp->response(pdu, target);
}
cout << endl;
}
void main(int argc, char **argv)
{
int trap_port;
if (argc < 2)
trap_port = 162; // no need to be root
else
trap_port = atoi(argv[1]);
//----------[ create a SNMP++ session ]-----------------------------------
int status;
Snmp::socket_startup(); // Initialize socket subsystem
Snmp snmp(status); // check construction status
if ( status != SNMP_CLASS_SUCCESS)
{
cout << "SNMP++ Session Create Fail, " << snmp.error_msg(status) << "\n";
}
OidCollection oidc;
TargetCollection targetc;
cout << "Trying to register for traps on port " << trap_port << "." << endl;
snmp.notify_set_listen_port(trap_port);
status = snmp.notify_register(oidc, targetc, callback, NULL);
if (status != SNMP_CLASS_SUCCESS)
{
cout << "Error register for notify (" << status << "): "
<< snmp.error_msg(status) << endl;
exit(1);
}
else
cout << "Waiting for traps/informs..." << endl;
snmp.start_poll_thread(1000);
cout << "press return to stop\n";
getc(stdin);
snmp.stop_poll_thread();
Snmp::socket_cleanup(); // Shut down socket subsystem
} 展开
3个回答
展开全部
看看snmp这个工程的log.cpp文件里的iob方法,估计只是声明了没有实现
更多追问追答
追问
我找了log.cpp里面根本就没有iob啊 log.h里面也没有iob啊
追答
你把你那log.h代码贴出来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
还是有对应的lib没有包含进来,所以会报这样的错误
追问
我就是想把这个控制台win32的程序变成mfc的 就是出现了这个问题啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询