无法创建用于在 Windows 中运行 SDL 游戏的可执行文件(错误 : previous declaration of SDL_main was . ..)

标签 c cross-compiling sdl-2

我在 ubuntu 中使用 atom 编辑器创建了一个带有 SDL2 库的游戏,并使用以下代码创建了一个 makefile 进行编译:

game: main.c LoadGame.c Events.c CreateTex.c CollisionDetection.c Render.c gameStatus.c
    gcc main.c LoadGame.c Events.c CreateTex.c CollisionDetection.c Render.c gameStatus.c -w -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -o game -lm -I.

现在我想创建一个 .exe,所以我创建了这个 makefile:

game: main.c LoadGame.c Events.c CreateTex.c CollisionDetection.c Render.c gameStatus.c
    i686-w64-mingw32-gcc main.c LoadGame.c Events.c CreateTex.c CollisionDetection.c Render.c gameStatus.c -w -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -o game.exe -lm -I.

但它给出了这个错误:


    In file included from /usr/i686-w64-mingw32/include/SDL2/SDL.h:32:0,
                     from main.c:2:
    main.c:8:5: error: conflicting types for ‘SDL_main’
     int main(int argc, char const *argv[]){
         ^
    /usr/i686-w64-mingw32/include/SDL2/SDL_main.h:117:39: note: previous declaration of ‘SDL_main’ was here
     tern C_LINKAGE SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[]);
                                         ^~~~~~~~
    makefile:5: recipe for target 'game' failed
    make: *** [game] Error 1


所以我需要一些帮助,以便我可以从我的源代码创建一个 .exe 文件以在 Windows 中运行它,同时

最佳答案

好吧,作为keltar提到看起来问题出在我的程序中,

int main(int argc, char const *argv[]) 
argv 数组是常量,如 here 中所述它不会工作。 所以正确的代码应该是:


    int main(int argc, char *argv[])

关于无法创建用于在 Windows 中运行 SDL 游戏的可执行文件(错误 : previous declaration of SDL_main was . ..),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57184191/

相关文章:

c++ - 为什么 gcc 编译器标志未知?

android - 如何为您的手机编译股票 android

c++ - 在arm-linux-gnueabihf-g++交叉编译期间出错。无法识别共享库文件

c++ - 是否有可能让 Visual Studio 2017 将 c++ 代码编译成 exe 以外的文件类型?

c++ - SDL2 窗口能否始终处于事件状态并位于 DirectX 窗口之上?

c++ - SDL 窗口 - 渲染 Sprite C++

c++ - SDL2 尝试裁剪纹理或表面

c - 我正在尝试将数字按升序添加到链表中。我可以解决什么问题?这是我的代码 :

c - 使用 -pg 编译的 gcc 不会生成 gprof 所需的二进制文件

c - 是否可以为数组名称分配一个新值?