Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error LNK2019 and LNK2001

Error LNK2019 and LNK2001

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 3.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    riken7
    wrote on last edited by
    #1

    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.

    raven-worxR 1 Reply Last reply
    0
    • R riken7

      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.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • R Offline
        R Offline
        riken7
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • R Offline
            R Offline
            riken7
            wrote on last edited by riken7
            #5

            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

            raven-worxR 1 Reply Last reply
            0
            • R riken7

              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

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @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.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              R 1 Reply Last reply
              0
              • R Offline
                R Offline
                riken7
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • raven-worxR raven-worx

                  @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.

                  R Offline
                  R Offline
                  riken7
                  wrote on last edited by
                  #8

                  @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.

                  VRoninV 1 Reply Last reply
                  0
                  • R riken7

                    @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.

                    VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #9

                    @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

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    1 Reply Last reply
                    1
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #10

                      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)

                      R 1 Reply Last reply
                      1
                      • mrjjM mrjj

                        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)

                        R Offline
                        R Offline
                        riken7
                        wrote on last edited by
                        #11

                        @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.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved