Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Facing error "undefined reference to __imp__ZN......."



  • Hello,
    I am new to QT and i am trying to configure the serial port for sending and receiving data.
    But while i configure the serial port i am facing below mentioned error.
    I am using QT creator and c++ for writing code.

    "C:\Users\Dipesh.Sharma\Documents\QT-Test\mainwindow.cpp:32: error: undefined reference to `__imp__ZN11QSerialPortC1EP7QObject'"

    #include<QtSerialPort/QSerialPort>
    #include<QtSerialPort/QSerialPortInfo>

    using namespace std;

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
    {

    QLabel *Image = new QLabel(this);
    QPixmap pixmap("C:/Users/Dipesh.Sharma/Documents/QT-Test/volansys.png");
    Image->setPixmap(pixmap);
    Image->setGeometry(150,-200,500,500);
    Image->show();
    
    QSerialPort *ser = new QSerialPort(this);
    ser->setParity(QSerialPort::NoParity);
    

    kindly help me in this issue if any of the more inputs are required please let know.


  • Lifetime Qt Champion

    Hi @Dipesh-Sharma,

    please show your .pro file.

    Regards



  • Hello aha,

    kindly find the .pro file

    #-------------------------------------------------

    Project created by QtCreator 2019-07-01T11:38:28

    #-------------------------------------------------

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = QT-Test
    TEMPLATE = app

    The following define makes your compiler emit warnings if you use

    any feature of Qt which has been marked as deprecated (the exact warnings

    depend on your compiler). Please consult the documentation of the

    deprecated API in order to know how to port your code away from it.

    DEFINES += QT_DEPRECATED_WARNINGS

    You can also make your code fail to compile if you use deprecated APIs.

    In order to do so, uncomment the following line.

    You can also select to disable deprecated APIs only up to a certain version of Qt.

    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

    CONFIG += c++11

    SOURCES +=
    main.cpp
    mainwindow.cpp

    HEADERS +=
    mainwindow.h

    FORMS +=
    mainwindow.ui

    Default rules for deployment.

    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target


  • Moderators

    hi @Dipesh-Sharma
    when you take a look the the documentation
    https://doc.qt.io/qt-5/qserialport.html

    You will see at the very top this box:

    0_1562133329135_8fc48a0f-0a6d-4ccc-876c-0a8b1f241031-image.png

    It tell's you, that you need to add the serialport module to your project file QT += serialport it is missing in your pro file.

    Add it, clean -> run qmake -> build and the error should go away.

    Remember every time you make changes in your pro file you should explicitly rerun qmake! It's not needed 100% of the time, but getting into the habit will save you time in the long run 😉



  • Hi @aha_1980

    Actually i debug around and came to know serialport widget need to be added in the .pro file.

    It resolved my issue.

    Thanks for your help.

    Regards,
    Dipesh Sharma.


  • Lifetime Qt Champion

    @Dipesh-Sharma

    Glad you figured it out. So please mark this topic as SOLVED. Thanks!


Log in to reply