Error LNK2019 and LNK2001



  • Hello,
    I have a problem when I'm compiling my project. I show an error ocurred.
    I have 25 errors, these errors are:

    mainwindow.obj:-1: error: LNK2019: símbolo externo "__declspec(dllimport) public: void __cdecl QSerialPort::setPortName(class QString const &)" (__imp_?setPortName@QSerialPort@@QEAAXAEBVQString@@@Z) sin resolver al que se hace referencia en la función "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
    

    and other example are

    mainwindow.obj:-1: error: LNK2001: símbolo externo "public: virtual __int64 __cdecl QSerialPort::bytesAvailable(void)const " (?bytesAvailable@QSerialPort@@UEBA_JXZ) sin resolver
    

    Mi code is:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QtCore/QtGlobal>
    
    #include <QMainWindow>
    
    #include <QtSerialPort/QSerialPort>
    #include <QPushButton>
    #include <QTimer>
    #include <QIODevice>
    #include <QTime>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
       Q_OBJECT
    
    public:
       explicit MainWindow(QWidget *parent = 0);
       ~MainWindow();
       void fill_array();
       void delay(int millisecondsToWait);
    
    
    /*private slots:
       void temporizador1();
       void temporizador2();
       void temporizador3();
       void temporizador4();
       void inicio();*/
    
    
    
    private:
       Ui::MainWindow *ui;
       QSerialPort *serial;
       QTimer *timer1, *timer2, *timer3, *timer4;
       QPushButton *aceptar;
       int primero[96];
       int segundo[92];
       int tercero[10];
       int cuarto[43];
       QString mensaje1, mensaje2, mensaje3, mensaje4;
    };
    
    #endif // MAINWINDOW_H
    

    and

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        serial= new QSerialPort(this);
        aceptar= new QPushButton(this);
        aceptar->setText("Aceptar");
        serial->setPortName("COM3");
        serial->setBaudRate(9600);
        serial->setParity(QSerialPort::NoParity);
        serial->setDataBits(QSerialPort::Data8);
        serial->setStopBits(QSerialPort::OneStop);
        serial->setFlowControl(QSerialPort::NoFlowControl);
        serial->open(QIODevice::ReadWrite);
    
        timer1=new QTimer(this);
        timer2=new QTimer(this);
        timer3= new QTimer(this);
        timer4= new QTimer(this);
    
        ui->verticalLayout->addWidget(aceptar);
        fill_array();
        delay(5000);
        serial->write(mensaje1.toLatin1());
        delay(5000);
        serial->write(mensaje2.toLatin1());
        delay(5000);
        serial->write(mensaje3.toLatin1());
        delay(2000);
        serial->write(mensaje4.toLatin1());
    
    
    
        /*connect(aceptar,SIGNAL(clicked()),this,SLOT(inicio()));
        connect(timer1,SIGNAL(timeout()),this,SLOT(temporizador1()));
        connect(timer2,SIGNAL(timeout()),this,SLOT(temporizador2()));
        connect(timer3,SIGNAL(timeout()),this,SLOT(temporizador3()));
        connect(timer4,SIGNAL(timeout()),this,SLOT(temporizador4()));*/
    
    
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    
    }
    
    
    void MainWindow::fill_array(){
        for(int i=0;i<=95;i++){
            primero[i]=7;
            mensaje1=mensaje1+ QString::number(primero[i]);
        }
        for(int i=0;i<=91;i++){
            segundo[i]=5;
            mensaje2=mensaje2+ QString::number(segundo[i]);
        }
        for (int i=0;i<=9;i++){
            tercero[i]=6;
            mensaje3=mensaje3+ QString::number(tercero[i]);
        }
        for(int i=0;i<=62;i++){
            cuarto[i]=3;
            mensaje4=mensaje4+QString::number(cuarto[i]);
        }
    
    }
    
    /*void MainWindow::temporizador1(){
       serial->write(mensaje1.toLatin1());
       timer1->stop();
       timer2->start(5000);
    }
    
    void MainWindow::temporizador2(){
        serial->write(mensaje2.toLatin1());
        timer2->stop();
        timer3->start(5000);
    }
    void MainWindow::temporizador3(){
        serial->write(mensaje3.toLatin1());
        timer3->stop();
        timer4->start(2000);
    }
    
    void MainWindow::temporizador4(){
        serial->write(mensaje4.toLatin1());
        timer4->stop();
        timer1->start(5000);
    }*/
    
    /*void MainWindow::inicio(){
        timer1->start(5000);
    }*/
    
    void delay( int millisecondsToWait )
    {
        QTime dieTime = QTime::currentTime().addMSecs( millisecondsToWait );
        while( QTime::currentTime() < dieTime )
        {
            QCoreApplication::processEvents( QEventLoop::AllEvents, 100 );
        }
    }
    
    

    I compile with MSVC2015 and qmake

    Thanks for your responses.


  • Moderators

    @riken7
    add QT += serialport to your .pro file



  • Now, I add QT += serialport, but errors LNK2019 and LNK 2001 go on happening

    #-------------------------------------------------
    #
    # Project created by QtCreator 2016-12-27T10:52:48
    #
    #-------------------------------------------------
    
    QT       += core gui
    QT       += serialport
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    
    TARGET = serie
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
            mainwindow.cpp
    
    HEADERS  += mainwindow.h
    
    FORMS    += mainwindow.ui
    

    thanks


  • Lifetime Qt Champion

    Hi,

    Did you re-run qmake or force a full re-build of your project ?



  • First, I did re-run the project and Now I do re-build my project.

    These error go on happening, I use build with debug.

    Images o my settings


  • Moderators

    @riken7
    to make sure:
    You should rerun qmake. Means right click on your project in QtCreator and choose "Run qmake" to update the makefiles and thus the linker commands.



  • This post is deleted!


  • @raven-worx
    Thanks, the project has compiled me perfectly but I have another problem when the program is executing, it crash.

    I am a noob with Qt and MSVC and I don't know solving the problem.

    Upload the images for yo can show that happening.

    [Problem Images](Thanks, the project has compiled me perfectly)

    I crew that It's a windows problem.



  • @riken7 said in Error LNK2019 and LNK2001:

    program is executing, it crash

    Did you check with a debugger, often this behaviour is due to errors in the program itself


  • Qt Champions 2016

    Hi
    make sure that [index] matches the len
    for all
    int primero[96];
    int segundo[92];
    int tercero[10];
    int cuarto[43];

    as this looks wrong
    for(int i=0;i<=62;i++){
    cuarto[i]=3; <<< is cuarto not ONLY 43? ( this can crash you)



  • @mrjj said in Error LNK2019 and LNK2001:

    Hi
    make sure that [index] matches the len
    for all
    int primero[96];
    int segundo[92];
    int tercero[10];
    int cuarto[43];

    as this looks wrong
    for(int i=0;i<=62;i++){
    cuarto[i]=3; <<< is cuarto not ONLY 43? ( this can crash you)

    thanks, it's the problem!, i didn't look.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.