Reputation: 448
Im trying to use QtCreator to create a project including SDL2. But SDL is failing to compile correctly and I can't see the error.
My QtCreator .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Psiora
TEMPLATE = app
SOURCES += main.cpp\
ui_mainwindow.cpp
HEADERS += ui_mainwindow.h
FORMS += ui_mainwindow.ui
INCLUDEPATH += "D:\devel\SDL2-2.0.3\i686-w64-mingw32\include\SDL2"
LIBS += -L"D:\devel\SDL2-2.0.3\i686-w64-mingw32\lib" \
-lmingw32 \
-mwindows \
-lSDL2main \
-lSDL2
Main.cpp
#include "ui_mainwindow.h"
#include <QApplication>
#define SDL_MAIN_HANDLED //Let QT Supply WinMain
#include "SDL.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
UI_mainWindow win;
win.show();
return app.exec();
}
Compiler errors
g++ -Wl,-subsystem,windows -mthreads -o debug\Psiora.exe debug/main.o debug/ui_mainwindow.o debug/moc_ui_mainwindow.o -lglu32 -lopengl32 -lgdi32 -luser32 -lqtmaind -LD:\devel\SDL2-2.0.3\i686-w64-mingw32\lib -lmingw32 -mwindows -lSDL2main -lSDL2 -LD:\devel\Qt\5.2.1\mingw48_32\lib -lQt5Widgetsd -lQt5Guid -lQt5Cored
D:\devel\SDL2-2.0.3\i686-w64-mingw32\lib/libSDL2main.a(SDL_windows_main.o): In function `console_main':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/main/windows/SDL_windows_main.c:140: undefined reference to `SDL_main' collect2.exe: error: ld returned 1 exit status
I don't understand why SDL is giving an undefined reference to sdl_Main, when it has been linked in the correct order. I also don't get where this "/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/main/windows/" has come from when there is no such path on my computer, nor have I added the path myself.
My understanding is the SDL_Main provides WinMain however I wish to use the WinMain provided by Qt instead so I have defined the SDL_MAIN_HANDLED define to stop SDL using SDL_Main.
Addition Information:
Upvotes: 1
Views: 1945
Reputation: 53215
Add this to your project file to solve this:
win32:QMAKE_LIBS_QT_ENGTRY -= -lqtmain
win32-g++:DEFINES -= QT_NEEDS_QMAIN
or
CONFIG-= windows
QMAKE_LFLAGS += $$QMAKE_LFLAGS_WINDOWS
Upvotes: 3