0
votes

How can I setup a plain c++ project and continue developing it using qt creator and qmake build system (in windows!)

My Qt Creator works perfectly fine with qt projects. I am using MSVC2017-64 as my compiler.

I tried to setup a project like this

myproject.pro

CONFIG -= qt
CONFIG += c++17
DEFINES -= UNICODE QT_LARGEFILE_SUPPORT

SOURCES += \
    main.cpp

HEADERS += \
    main.h

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

main.cpp

#include "main.h"
#include <iostream>

int main(int argsCount, char** argsArray) {

    puts("Hello, World!");

    return 0;
}

main.h

#ifndef MAIN_H
#define MAIN_H


#endif // MAIN_H

And here is how my project page looks like: qt creator project setup page

But after all this when I try to build/compile I get this error:

MSVCRTD.lib(exe_winmain.obj):-1: error: LNK2019: unresolved external symbol WinMain referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

debug\WAVE2.exe:-1: error: LNK1120: 1 unresolved externals

What am I missing here?

2

2 Answers

2
votes

I believe you need to specify that this is a console application. You can do this by adding CONFIG += console or CONFIG += cmdline. The latter superseeds the former for cross-platform. See the qmake variable reference.

Alternatively, if your application is indeed a GUI application (but through other means than Qt), you would specify CONFIG += windows.

Both these variables will add appropriate libraries, which you are currently missing.

1
votes

In addition to ypnos answer, you can also use a project template.

In Qt creator > New Project > Non-Qt Project > Plain C++ Application. This will create everything you need.

New project with Qt

The .pro file:

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

SOURCES += \
        main.cpp