安装 qtSerialPort 库

安装 qtSerialPort 库

我想在 precise1-Ubuntu 中安装 qtserialport。我使用 git 获取了源目录。接下来我下载 lib-qt4-dev 和 qmake。我运行了 qmake。它运行正常。但是,make 失败并出现以下错误:

    cd src/ && make -f Makefile 
make[1]: Entering directory `/home/saman/5.0.1/serialPortSrc/qtserialport/src'
cd serialport/ && make -f Makefile 
make[2]: Entering directory `/home/saman/5.0.1/serialPortSrc/qtserialport/src/serialport'
make[2]: Nothing to be done for `first'.
make[2]: Leaving directory `/home/saman/5.0.1/serialPortSrc/qtserialport/src/serialport'
make[1]: Leaving directory `/home/saman/5.0.1/serialPortSrc/qtserialport/src'
cd examples/ && make -f Makefile 
make[1]: Entering directory `/home/saman/5.0.1/serialPortSrc/qtserialport/examples'
cd cenumerator/ && make -f Makefile 
make[2]: Entering directory `/home/saman/5.0.1/serialPortSrc/qtserialport/examples/cenumerator'
g++ -Wl,-O1 -o cenumerator main.o    -L/usr/lib/i386-linux-gnu -lQtGui -lQtCore -lpthread 
main.o: In function `QList<QSerialPortInfo>::free(QListData::Data*) [clone .isra.1]':
main.cpp:(.text+0x47): undefined reference to `QSerialPortInfo::~QSerialPortInfo()'
main.o: In function `QList<QSerialPortInfo>::detach_helper(int)':
main.cpp:(.text._ZN5QListI15QSerialPortInfoE13detach_helperEi[QList<QSerialPortInfo>::detach_helper(int)]+0x68): undefined reference to `QSerialPortInfo::QSerialPortInfo(QSerialPortInfo const&)'
main.cpp:(.text._ZN5QListI15QSerialPortInfoE13detach_helperEi[QList<QSerialPortInfo>::detach_helper(int)]+0xc3): undefined reference to `QSerialPortInfo::~QSerialPortInfo()'
main.o: In function `main':
main.cpp:(.text.startup+0x5e): undefined reference to `QSerialPortInfo::availablePorts()'
main.cpp:(.text.startup+0x10f): undefined reference to `QSerialPortInfo::isBusy() const'
main.cpp:(.text.startup+0x16b): undefined reference to `QSerialPortInfo::hasProductIdentifier() const'
main.cpp:(.text.startup+0x1bb): undefined reference to `QSerialPortInfo::hasVendorIdentifier() const'
main.cpp:(.text.startup+0x212): undefined reference to `QSerialPortInfo::manufacturer() const'
main.cpp:(.text.startup+0x24a): undefined reference to `QSerialPortInfo::description() const'
main.cpp:(.text.startup+0x282): undefined reference to `QSerialPortInfo::systemLocation() const'
main.cpp:(.text.startup+0x2ba): undefined reference to `QSerialPortInfo::portName() const'
main.cpp:(.text.startup+0x644): undefined reference to `QSerialPortInfo::productIdentifier() const'
main.cpp:(.text.startup+0x674): undefined reference to `QSerialPortInfo::vendorIdentifier() const'
collect2: ld returned 1 exit status
make[2]: *** [cenumerator] Error 1
make[2]: Leaving directory `/home/saman/5.0.1/serialPortSrc/qtserialport/examples/cenumerator'
make[1]: *** [sub-cenumerator-make_default-ordered] Error 2
make[1]: Leaving directory `/home/saman/5.0.1/serialPortSrc/qtserialport/examples'
make: *** [sub-examples-make_default-ordered] Error 2

尽管 make 失败了,但我现在可以将 qtserialport 标头包含到我的项目中。关于失败,我检查了 main.cpp,它包含 serialPortSrcInfo.so,这个 .so 文件在调用 qmake 时已经生成。我该如何解决这个问题?

答案1

据我所知,它基于 Qt5+。我在我的项目 (pilotnavigator) 中使用 Qtserial。我的 QTSDK 5+ 是本地安装的(不是通过 apt)。这些是说明。

  • 将 qtplayground-qtserialport 文件夹复制到本地文件夹(最好是您的 Qt 项目所在的文件夹)。示例:~/yourqtprojectfolder/pilotnavigator/qtplayground-qtserialport
  • 在 pilotnavigator 文件夹中创建同级 build 文件夹,名为 qtplayground-qtserialport-build。示例:~/yourqtprojectfolder/pilotnavigator/qtplayground-qtserialport-build

找出 qmake 的位置。通常它位于你的 Qt5 文件夹中,可能是 ~/Qt5x.xx/5.xx/gcc_64/bin

打开Linux终端

cd 到 qtplayground-qtserialport-build 文件夹。示例cd ~/yourqtprojectfolder/pilotnavigator/qtplayground-qtserialport-build

运行 qmake。例如:

~/Qt5x.x.x/5.x.x/gcc_64/bin/qmake ~/yourqtprojectfolder/pilotnavigator/qtplayground-qtserialport/qtserialport.pro
make

(如果出现缺少文件 libudev.h 的错误,则需要安装 libudev-dev 库,例如sudo apt-get install libudev-dev

sudo make install

相关内容