qextserialport 1.1 串口编译

本文详细介绍了在Windows上使用QT 4.3.2和VC++ 2003编译qextserialport 1.1的步骤,包括下载源码、修改配置、编译生成动态库和静态库,以及解决编译过程中遇到的错误。同时,还提供了在Linux环境下生成静态库的方法和注意事项。
摘要由CSDN通过智能技术生成

编译环境:
1、qextserialport 1.1
2、QT 4.3.2
3、VC++ 2003

1.在官网下载QextSerialPort最新版qextserialport-1.1.tar.gz,解压到qextserialport-1.1目录中。
2.将qextserialport-1.1目录下的qextserialport拷贝到Qt安装目录下的src目录中
3.进入src目录下的qextserialport目录,输入一下命令编译:
qmake
nmake
4.然后在qextserialport目录下的build目录下可得到qextserialport.dll,qextserialport.prl,libqextserialport.a三个文件,将qextserialport.dll复制到Qt安装目录下的bin目录中,将qextserialport.prl,libqextserialport.a复制到Qt安装目录下的lib目录中。(默认一般生成DLL和PRL,生成LIB参见附录步骤)

Linux下通过Config += static 生成静态库libqextserialport.a
5.在Qt安装目录下的include目录下的Qt目录中新建文件qextserialport.h,文件内容为:
#include "http://www.cnblogs.com/src/qextserialport/qextserialport.h"
并将该文件复制到Qt安装目录下的include目录下的QtGui目录中,并在该目录中再新建一个文件QextSerialPort(无扩展名),该文件内容为:
#include “qextserialport.h”
6.将src/qextserialport目录中的example目录拷贝到硬盘的其他地方,删除例子目录下的Makefile.Release, Makefile, Makefile.Debug,README和QESPTA.pro几个文件。
7.打开例子目录中的main.cpp和QespTest.cpp文件,修改#include <qextserialport.h>为#include <QextSerialPort>
8.编译自带EXAMPLE:进入EXAMPLE目录,输入:
Qmake –project
得到工程文件qespta.pro,打开该工程文件,如果当前系统为win32,加入语句:
LIBS          += -lqextserialport
win32:DEFINES = _TTY_WIN_ QWT_DLL QT_DLL
如果当前系统为unix/linux,加入语句:
LIBS          += -lqextserialport
unix:DEFINES   = _TTY_POSIX_
9.编译
qmake
nmake
如果编译成功证明已经扩展成功
10.该扩展帮助文档位于src/qextserialport目录中,可供查阅
注意,此扩展方法将类QextSerialPort扩展至QtGui下,请勿将类QextSerialPort误认为QtGui的一部分

附录:如何生成qextserialport.lib。
qmake默认是生成动态库版本,静态链接文件生成需要修改qextserialport.pro。(关于qmake参数说明可参见: http://www.cppblog.com/mydriverc/articles/32728.html
1、打开qextserialport.pro
2、修改
CONFIG                 += warn_on qt thread

CONFIG                 += zhuw.itworld2.com/qtcompilation.aspx

注意:(http://www.itworld2.com/qtcompilation.aspx
编译时可能会遇到如下错误:previous declaration 'long int InterlockedIncrement(long int*)' here

此为qt的bug需要修改源代码(Qt\4.4.3\src\corelib\arch\qatomic_windows.h),
原文件如下:

  1. #if !(defined Q_CC_BOR) || (__BORLANDC__ < 0x560)   
  2. extern "C" {   
  3. __declspec(dllimport) long __stdcall InterlockedCompareExchange(long *, long, long);   
  4. __declspec(dllimport) long __stdcall InterlockedIncrement(long *);   
  5. __declspec(dllimport) long __stdcall InterlockedDecrement(long *); __declspec(dllimport) long __stdcall InterlockedExchange(long *, long);   
  6. __declspec(dllimport) long __stdcall InterlockedExchangeAdd(long *, long);   
  7. }   
  8. #else   
  9. extern "C" {   
  10. __declspec(dllimport) long __stdcall InterlockedCompareExchange(long volatile*, long, long);   
  11. __declspec(dllimport) long __stdcall InterlockedIncrement(long volatile*);   
  12. __declspec(dllimport) long __stdcall InterlockedDecrement(long volatile*);   
  13. __declspec(dllimport) long __stdcall InterlockedExchange(long volatile*, long);   
  14. __declspec(dllimport) long __stdcall InterlockedExchangeAdd(long volatile*, long);   
  15. }   
  16. #endif   
  17.   
  18. 修改如下:   
  19.   
  20. extern "C" {   
  21. __declspec(dllimport) long __stdcall InterlockedCompareExchange(long volatile*, long, long);   
  22. __declspec(dllimport) long __stdcall InterlockedIncrement(long volatile*);   
  23. __declspec(dllimport) long __stdcall InterlockedDecrement(long volatile*);   
  24. __declspec(dllimport) long __stdcall InterlockedExchange(long volatile*, long);   
  25. __declspec(dllimport) long __stdcall InterlockedExchangeAdd(long volatile*, long);   
  26. }   
  27. // #endif 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值