小编akn*_*nay的帖子

如何将 QSerialPort 模块添加到 CMake 中?

我想将 QSerialPort 模块添加到 CMake 中。根据我的理解,我需要将 QT += serialport 添加到 *.pro 中。我只想使用 CMake。所以我尝试编译简单的 CMake 文件,但它有错误。QtCore 正在工作,因为 qDebug 可以毫无问题地显示。

我得到的错误是:

undefined reference to `QSerialPort::QSerialPort(QObject*)'
undefined reference to `QSerialPort::~QSerialPort()'
undefined reference to `QSerialPort::~QSerialPort()'
Run Code Online (Sandbox Code Playgroud)

这是简单的 main.cpp 文件。

#include <iostream>
#include <QObject>
#include <QDebug>
#include <QCoreApplication>
#include <QtSerialPort/QSerialPort>

using namespace std;

int main() {
    QSerialPort serialPort; //this line gives error
    qDebug()<<"Hello Qt"; //this line is working as normal
    cout << "Hello, World!" << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是简单的 CMake 文件。

cmake_minimum_required(VERSION 3.3)
project(untitled1)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} …
Run Code Online (Sandbox Code Playgroud)

c++ qt serial-port cmake

4
推荐指数
1
解决办法
3999
查看次数

标签 统计

c++ ×1

cmake ×1

qt ×1

serial-port ×1