我試圖教會自己如何在Qt Creator中使用SDL2,但不斷進入這些「只讓我編寫代碼」的情況。目前,我只是想打開一個窗口,上面有綠色的圖片(做一個教程),但我得到這個錯誤:無法運行SDL2項目,「無法執行」「:%1不是有效的Win32應用程序」
Cannot execute "": %1 not a valid Win32-application
我使用MinGW的5.3.0 32bit2因爲編譯器和I」已經設法運行沒有這個錯誤的其他項目。我試着修改構建和運行配置,但沒有任何運氣。目前我(必需的)運行的配置是這樣的:
Executable C:\...\sdl_test\debug\sdl_test.exe
Working directory: C:\...\sdl_test
也可對照,這裏的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;
}
感到絕望,因爲我只是想上打開一個窗口,一個綠色的矩形它......這是太多要問?!
編輯: 這是我的.pro文件
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
如果你'C雙擊,會發生什麼:\ ... \ sdl_test \在資源管理器的調試\ sdl_test.exe'?如果從'cmd'運行'C:\ ... \ sdl_test \ debug \ sdl_test.exe',會發生什麼情況? – Paul
如果我雙擊sdl_test.exe:「此操作系統不支持此應用程序」 同樣的事情,如果我嘗試從cmd運行。我正在運行一個64位操作系統。 – Borjee
只是一個瘋狂的想法 - 你確定你正在使用的編譯器生成Windows的二進制文件?也許這是一個Linux交叉編譯器。如果你的'MinGW'中有'file'工具,你可以運行'file sdl_test.exe'並看看它會打印什麼? – Paul