Results 1 to 3 of 3

Thread: LNK2019 error using multiple source files

  1. #1
    Join Date
    Dec 2019
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Lightbulb LNK2019 error using multiple source files

    Hello community,

    I can't run my hello world program, I get LNK2019 error.

    main.cpp
    Qt Code:
    1. #include <QCoreApplication>
    2. #include "hello.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication app(argc, argv);
    7.  
    8. Hello *hi = new Hello();
    9.  
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    hello.h
    Qt Code:
    1. #ifndef HELLO_H
    2. #define HELLO_H
    3.  
    4. class Hello{
    5. public:
    6. Hello();
    7. };
    8.  
    9. #endif // HELLO_H
    To copy to clipboard, switch view to plain text mode 

    hello.cpp
    Qt Code:
    1. #include <iostream>
    2.  
    3. class Hello{
    4. public:
    5. Hello(){
    6. std::cout << "hello world" << std::endl;
    7. }
    8. };
    To copy to clipboard, switch view to plain text mode 

    myproject.pro
    Qt Code:
    1. QT -= gui
    2.  
    3. CONFIG += c++11 console
    4. CONFIG -= app_bundle
    5. DEFINES += QT_DEPRECATED_WARNINGS
    6. SOURCES += \
    7. hello.cpp \
    8. main.cpp
    9.  
    10. # Default rules for deployment.
    11. qnx: target.path = /tmp/$${TARGET}/bin
    12. else: unix:!android: target.path = /opt/$${TARGET}/bin
    13. !isEmpty(target.path): INSTALLS += target
    14.  
    15. HEADERS += \
    16. hello.h
    To copy to clipboard, switch view to plain text mode 

    It works fine without creating Hello object.
    Last edited by supernatrium; 6th December 2019 at 17:21.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: LNK2019 error using multiple source files

    Did you run qmake again after changing your .pro file to add the hello.* entries?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: LNK2019 error using multiple source files

    You define your class Hello a second time in hello.cpp

  4. The following user says thank you to ChristianEhrlicher for this useful post:

    d_stranz (7th December 2019)

Similar Threads

  1. Replies: 12
    Last Post: 1st August 2014, 01:45
  2. Compilation Error LNK2019 on QTest::qSleep
    By chiaminhsu in forum Qt Programming
    Replies: 3
    Last Post: 1st February 2013, 04:21
  3. Compilation Error LNK2019
    By Afandi in forum Newbie
    Replies: 3
    Last Post: 23rd December 2012, 16:14
  4. Multiple source files per ui
    By squidge in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2009, 18:32
  5. Error: Using Multiple files
    By 3nc31 in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2007, 10:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.