Results 1 to 4 of 4

Thread: non-qt console app using QtCreator

  1. #1
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default non-qt console app using QtCreator

    I am having problems linking non-qt console application using qtCreator, vs2015 kit.

    The error I am getting is:
    MSVCRTD.lib(exe_winmain.obj):-1:
    error: LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

    I will appreciate advise or comment what I am doing wrong here.

    My .pro file is:

    Qt Code:
    1. TEMPLATE = app
    2. CONFIG += console c++11
    3. CONFIG -= qt
    4.  
    5. LIBS = kernel32.lib \
    6. user32.lib \
    7. gdi32.lib
    8.  
    9. #LIBS += -L"$(BOOST)/stage/lib"
    10. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 


    My main.cpp file is:
    Qt Code:
    1. #include <iostream>
    2. using namespace std;
    3.  
    4. int main() //(int argc, char * argv[]) , I tried main with and without arguments, with and without "void"
    5. {
    6. cout << "Hello World!" << endl;
    7. return 0;
    8. }
    To copy to clipboard, switch view to plain text mode 

  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: non-qt console app using QtCreator

    The link error you are getting is because the compiler is being told to build a Windows GUI app, not a command line console app. The "_WinMain@16" is the entry point for a GUI app.

    Something is probably wrong in the project configuration. If it was a Visual Studio project, I could tell you, but Qt Creator and qmake do some mysterious things behind the scenes. If you can get access to the compiler command line that Qt Creator is using, you might find something like "WIN32" defined, or "/SUBSYSTEM:WINDOWS" on the linker command line. In particular, the linker option tells it to use the WinMain entry polt. This should say CONSOLE instead.

    Maybe there's a CONFIG -= gui you can also add?
    <=== 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. The following user says thank you to d_stranz for this useful post:

    TorAn (4th October 2016)

  4. #3
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: non-qt console app using QtCreator

    Qt Code:
    1. This configuration works...
    2. CONFIG = console
    3. CONFIG += c++11
    4. CONFIG -= qt
    To copy to clipboard, switch view to plain text mode 

    (at least it links and builds exe)
    Last edited by TorAn; 4th October 2016 at 22:51.

  5. #4
    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: non-qt console app using QtCreator

    Ah, good to know - your first version had CONFIG += console, which means you probably hadn't cleared the setting that tells qmake to configure a Windows app.
    <=== 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.

Similar Threads

  1. QtCreator debug in console mode
    By stef13013 in forum Qt Tools
    Replies: 0
    Last Post: 8th February 2011, 15:34
  2. Replies: 2
    Last Post: 24th December 2010, 05:30
  3. QtCreator 2.0 crashes application working in QtCreator 1.3
    By been_1990 in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2010, 12:58
  4. QT Console app
    By yorkshireflatcap in forum Newbie
    Replies: 14
    Last Post: 22nd June 2010, 20:57
  5. Replies: 1
    Last Post: 10th February 2010, 07:28

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.