PDA

View Full Version : non-qt console app using QtCreator



TorAn
4th October 2016, 14:15
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:


TEMPLATE = app
CONFIG += console c++11
CONFIG -= qt

LIBS = kernel32.lib \
user32.lib \
gdi32.lib

#LIBS += -L"$(BOOST)/stage/lib"
SOURCES += main.cpp


My main.cpp file is:

#include <iostream>
using namespace std;

int main() //(int argc, char * argv[]) , I tried main with and without arguments, with and without "void"
{
cout << "Hello World!" << endl;
return 0;
}

d_stranz
4th October 2016, 16:51
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?

TorAn
4th October 2016, 19:59
This configuration works...
CONFIG = console
CONFIG += c++11
CONFIG -= qt

(at least it links and builds exe)

d_stranz
5th October 2016, 01:18
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.