'Can't run SDL2 project, "Cannot execute "": %1 Not a valid Win32-application"
I'm trying to teach myself how to use SDL2 with Qt Creator but keep getting into these "just let me code" situations. Currently, I'm just trying to open a window with a green picture on it (doing a tutorial) but I get this error:
Cannot execute "": %1 not a valid Win32-application
I'm using MinGw 5.3.0 32bit2 as the compiler and I've managed to run other projects without this error. I tried tinkering with the Build and Run configurations, but haven't had any luck. Currently my (essential) Run configurations look like this:
Executable C:\...\sdl_test\debug\sdl_test.exe
Working directory: C:\...\sdl_test
Also for reference, here's main.cpp:
#include <iostream>
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
using namespace std;
int main()
{
bool quit = false;
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = nullptr;
window = SDL_CreateWindow("MVP", 100, 100, 600, 400,
SDL_WINDOW_SHOWN);
if(window == nullptr){
cout << "Window could not be created." << endl;
return 0;
}
SDL_Renderer* renderer = nullptr;
renderer = SDL_CreateRenderer(window, -1,
SDL_RENDERER_ACCELERATED);
SDL_Event* mainEvent = new SDL_Event();
SDL_Texture* grass_image = NULL;
grass_image = IMG_LoadTexture(renderer, "grass.bmp");
SDL_Rect grass_rect;
grass_rect.x = 10;
grass_rect.y = 50;
grass_rect.w = 250;
grass_rect.h = 250;
while(!quit && mainEvent->type != SDL_QUIT){
SDL_PollEvent(mainEvent);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, grass_image, NULL, &grass_rect);
SDL_RenderPresent(renderer);
}
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
delete mainEvent;
return 0;
}
Feeling hopeless, since I just want to open a window with a green rectangle on it... is that too much to ask?!
EDIT: Here's my .pro file
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
win32: LIBS += -L$$PWD/../../../../SDL2-2.0.5/i686-w64-mingw32/lib/ -lmingw32 -lSDL2main -lSDL2
INCLUDEPATH += $$PWD/../../../../SDL2-2.0.5/i686-w64-mingw32/include
DEPENDPATH += $$PWD/../../../../SDL2-2.0.5/i686-w64-mingw32/include
win32: LIBS += -L$$PWD/../../../../SDL2_image-2.0.1/i686-w64-mingw32/lib/ -lmingw32 -lSDL2_image
INCLUDEPATH += $$PWD/../../../../SDL2_image-2.0.1/i686-w64-mingw32/include
DEPENDPATH += $$PWD/../../../../SDL2_image-2.0.1/i686-w64-mingw32/include
win32:QMAKE_LFLAGS += -shared
Solution 1:[1]
The code you are showing to us works for Linux and any sane system :)
There could be a few issues for your problem:
1 - you are trying to run a 64 bit application in a 32 bit system
2 - your dll's could be corrupt
3 - your SDL dll's could be compiled with Microsoft Visual Studio (and you would need to get dll's generated with MinGW)
also, you should pass a few flags to the compiler, since you told us that you are using Qt Creator, possibly you have a projectname.pro file or a CMakeLists.txt
discover what you have, and pass those flags to the compiler:
-Wl,-subsystem,windows
and link against those libraries
-lmingw32 -lSDL2main -lSDL2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tomaz Canabrava |
