当前位置: 技术问答>linux和unix
linux QT下 C++调用库的问题,请熟悉QT编程的朋友帮忙看一下。
来源: 互联网 发布时间:2016-03-08
本文导语: //--------头文件"PowerCtrl.h" ----------------------------------------------------- #ifndef _POWERCTRL_H_ #define _POWERCTRL_H_ #ifdef __cplusplus extern "C" { #endif #define FALSE 0 #define TRUE 1 int Power_Active(); char *Power_GetPowerP...
//--------头文件"PowerCtrl.h" -----------------------------------------------------
#ifndef _POWERCTRL_H_
#define _POWERCTRL_H_
#ifdef __cplusplus
extern "C" {
#endif
#define FALSE 0
#define TRUE 1
int Power_Active();
char *Power_GetPowerPort();
int Power_ActiveCOMM(int ac);
int Power_OpenX(int GV,int XV);
int Power_CloseX(int GV,int XV);
void Power_OpenAll();
void Power_CloseAll();
int Power_OpenGroup(int GV);
int Power_CloseGroup(int GV);
int Power_OpenGroupX(int GV, int HX, int DX);
int Power_SetHandNO(int GV, int XV, int CD);
int Power_SetHandPW(int PW);
int Power_SetHandNOA(int XV,int CD);
int Power_CheckHandNO(int GV,int XV);
int Power_HandOpenX(int CD);
int Power_HandCloseX(int CD);
void Power_HandOpenAll();
void Power_HandCloseAll();
void Power_HandLock();
int Power_HandUnLock(int PW);
int Power_CheckGroupStatus(int GV);
void Power_CheckEquipmentsLink();
void Power_EquipmentsReset();
int Power_SetEquipmentsID(int GV);
int Power_SetPowerPort(const char * vPort, int vBuand);
char *Statuslist_readGV(int GV);
void Statuslist_clear();
#ifdef __cplusplus
}
#endif
#endif
//----------------------------头文件"PowerCtrl.h" END-----------------------------
//----------------------------头文件"from1.ui.h" 中调用-------------------------------
#include
#include
#include "PowerCtrl.h"
void Form1::openClick_Slot()
{
QString str1 =comboBox1->currentText();
const char *c_str2 = str1.latin1();
Power_SetPowerPort(c_str2 , 1200);
if (Power_ActiveCOMM(1)==1)
{
pushButton8->setEnabled(false);
pushButton9->setEnabled(true);
}
else
{
pushButton8->setEnabled(true);
pushButton9->setEnabled(false);
}
}
void Form1::closeClick_Slot()
{
if (Power_ActiveCOMM(0)==1)
{
pushButton8->setEnabled(true);
pushButton9->setEnabled(false);
}
else
{
pushButton8->setEnabled(false);
pushButton9->setEnabled(true);
}
}
//--------头文件"PowerCtrl.h" END-----------------------------------------------------
wh@ubuntu:~/文档/powertest$ qmake powertest.pro
wh@ubuntu:~/文档/powertest$ make
g++ -Wl,-rpath,/usr/share/qt3.3.6/lib -o powertest .obj/main.o .obj/form1.o .obj/moc_form1.o -L/usr/share/qt3.3.6/lib -L/usr/X11R6/lib -L/home/wh/文档/powertest -lqt -lXext -lX11 -lm
//报以下的错误
.obj/form1.o: In function `Form1::closeClick_Slot()':
form1.cpp:(.text+0x82): undefined reference to `Power_ActiveCOMM(int)'
.obj/form1.o: In function `Form1::openClick_Slot()':
form1.cpp:(.text+0x137): undefined reference to `Power_SetPowerPort(char const*, int)'
form1.cpp:(.text+0x143): undefined reference to `Power_ActiveCOMM(int)'
collect2: ld returned 1 exit status
make: *** [powertest] Error 1
//库文件 PowerCtrl.so 放在/home/wh/文档/powertest目录下
#ifndef _POWERCTRL_H_
#define _POWERCTRL_H_
#ifdef __cplusplus
extern "C" {
#endif
#define FALSE 0
#define TRUE 1
int Power_Active();
char *Power_GetPowerPort();
int Power_ActiveCOMM(int ac);
int Power_OpenX(int GV,int XV);
int Power_CloseX(int GV,int XV);
void Power_OpenAll();
void Power_CloseAll();
int Power_OpenGroup(int GV);
int Power_CloseGroup(int GV);
int Power_OpenGroupX(int GV, int HX, int DX);
int Power_SetHandNO(int GV, int XV, int CD);
int Power_SetHandPW(int PW);
int Power_SetHandNOA(int XV,int CD);
int Power_CheckHandNO(int GV,int XV);
int Power_HandOpenX(int CD);
int Power_HandCloseX(int CD);
void Power_HandOpenAll();
void Power_HandCloseAll();
void Power_HandLock();
int Power_HandUnLock(int PW);
int Power_CheckGroupStatus(int GV);
void Power_CheckEquipmentsLink();
void Power_EquipmentsReset();
int Power_SetEquipmentsID(int GV);
int Power_SetPowerPort(const char * vPort, int vBuand);
char *Statuslist_readGV(int GV);
void Statuslist_clear();
#ifdef __cplusplus
}
#endif
#endif
//----------------------------头文件"PowerCtrl.h" END-----------------------------
//----------------------------头文件"from1.ui.h" 中调用-------------------------------
#include
#include
#include "PowerCtrl.h"
void Form1::openClick_Slot()
{
QString str1 =comboBox1->currentText();
const char *c_str2 = str1.latin1();
Power_SetPowerPort(c_str2 , 1200);
if (Power_ActiveCOMM(1)==1)
{
pushButton8->setEnabled(false);
pushButton9->setEnabled(true);
}
else
{
pushButton8->setEnabled(true);
pushButton9->setEnabled(false);
}
}
void Form1::closeClick_Slot()
{
if (Power_ActiveCOMM(0)==1)
{
pushButton8->setEnabled(true);
pushButton9->setEnabled(false);
}
else
{
pushButton8->setEnabled(false);
pushButton9->setEnabled(true);
}
}
//--------头文件"PowerCtrl.h" END-----------------------------------------------------
wh@ubuntu:~/文档/powertest$ qmake powertest.pro
wh@ubuntu:~/文档/powertest$ make
g++ -Wl,-rpath,/usr/share/qt3.3.6/lib -o powertest .obj/main.o .obj/form1.o .obj/moc_form1.o -L/usr/share/qt3.3.6/lib -L/usr/X11R6/lib -L/home/wh/文档/powertest -lqt -lXext -lX11 -lm
//报以下的错误
.obj/form1.o: In function `Form1::closeClick_Slot()':
form1.cpp:(.text+0x82): undefined reference to `Power_ActiveCOMM(int)'
.obj/form1.o: In function `Form1::openClick_Slot()':
form1.cpp:(.text+0x137): undefined reference to `Power_SetPowerPort(char const*, int)'
form1.cpp:(.text+0x143): undefined reference to `Power_ActiveCOMM(int)'
collect2: ld returned 1 exit status
make: *** [powertest] Error 1
//库文件 PowerCtrl.so 放在/home/wh/文档/powertest目录下
|
仅仅加了头文件是不行的!
还需要连接 PowerCtrl.so 才行.
ln -s PowerCtrl.so libPowerCtrl.so
gcc -lPowerCtrl
还需要连接 PowerCtrl.so 才行.
ln -s PowerCtrl.so libPowerCtrl.so
gcc -lPowerCtrl