我收到以下错误。根据最后一行,我认为这是一个链接器错误。但是,我真的不知道我在说什么。:) 我是初学者。如果您碰巧发现任何其他蹩脚点,请告诉我!
错误:对AttachHandler(_CPhidget*, void*)'
error: undefined reference to
DetachHandler(_CPhidget*, void*)' 的未定义引用 错误:对ErrorHandler(_CPhidget*, void*, int, char const*)'
error: undefined reference to
数据的未定义引用(_CPhidgetBridge*, void*, int, double)' :-1: 错误: collect2: ld 返回 1 个退出状态
我有一个名为 eventhandlers.h 的头文件,其中包含:
#ifndef EVENTHANDLERS_H
#define EVENTHANDLERS_H
#include <phidget21.h>
int CCONV AttachHandler(CPhidgetHandle SENSOR, void *userptr);
int CCONV DetachHandler(CPhidgetHandle SENSOR, void *userptr);
int CCONV ErrorHandler(CPhidgetHandle SENSOR, void *userptr, int ErrorCode, const char *DESCR);
int CCONV Data(CPhidgetBridgeHandle SENSOR, void *userptr, int index, double val);
#endif // EVENTHANDLERS_H
我试图在源文件名 quadbridge.cpp PARTIAL CODE中将 AttachHandler 和其他参数作为 CPhidget_Set_OnAttach_Handler() 的参数传递:
#include "stdlib.h"
#include "quadbridge.h"
#include "eventhandlers.h"
QuadBridge::QuadBridge(int numOfSensors, int PhidgetID)
{
this->SERIAL = 140800;
//this->SERIAL = 137723;
this->bridge = 0;
CPhidgetBridge_create(&bridge);
setEventHandlers();
if(setAttachController(PhidgetID))
{
getNumOfSensorsAttached(numOfSensors);
initSensors();
}
else
{
exit(1);
}
}
QuadBridge::~QuadBridge()
{
CPhidget_close((CPhidgetHandle)bridge);
CPhidget_delete((CPhidgetHandle)bridge);
}
void QuadBridge::setEventHandlers()
{
CPhidget_set_OnAttach_Handler((CPhidgetHandle)bridge, AttachHandler, 0);
CPhidget_set_OnDetach_Handler((CPhidgetHandle)bridge, DetachHandler, 0);
CPhidget_set_OnError_Handler((CPhidgetHandle)bridge, ErrorHandler, 0);
CPhidgetBridge_set_OnBridgeData_Handler(bridge, Data, 0);
CPhidget_open((CPhidgetHandle)bridge, SERIAL);
}
最后——我把整个事情都搞定了。
#include "palmtools.h"
#include "QuadBridge.h"
#include <QApplication>
QuadBridge *qb;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
PalmTools w;
w.show();
qb = new QuadBridge(4);
return a.exec();
}
谢谢您的帮助!