【问题标题】:SDL application exits without entering main - SDL ImageSDL 应用程序退出而不进入 main - SDL Image
【发布时间】:2020-12-14 17:12:46
【问题描述】:

我有一个应用程序在 Ubuntu 上运行良好,但在 Windows 上启动时立即退出,没有任何错误。

好像没有进入main()函数。

应用程序已编译且没有错误,它使用 SDL_image.h。当(在同一个应用程序中)使用 SDL Image 的代码不存在时,应用程序运行良好。

在.exe目录下有所有需要的dll,SDL2.dll、libjpeg-9.dll、libpng16-16.dll、libtiff-5.dll、libwebp-7.dll、SDL2_image.dll和zlib1.dll.

IMG_Init() 在任何其他图像函数之前以这种方式调用:

(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG)

而且,正如我之前所说,该应用程序在 Ubuntu 上运行没有问题。

这是一个可重现的例子。

此代码有效:

制作文件

CC = gcc -fno-pie -no-pie -m32
CFLAGS = -IC:/sdl2/include -O0 -ggdb
LIBS = -LC:/sdl2/lib/x86 -lSDL2main -lSDL2

all:
    $(CC) $(CFLAGS) main.c $(LIBS) -o application.exe

main.c

#include <stdio.h>
#include "SDL.h"


int main(int argc, char **argv)
{
    if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
    {
        SDL_Log("SDL fails to initialize video subsystem!\n%s", SDL_GetError());
        return -1;
    }
    else
        printf("SDL Video was initialized fine!\n");

    return 0;
}

这段代码,在我使用 SDL Image 库的地方,什么都不做,没有错误,立即退出:

制作文件

CC = gcc -fno-pie -no-pie -m32
CFLAGS = -IC:/sdl2/include -IC:/sdl2_image/include -O0 -ggdb
LIBS = -LC:/sdl2/lib/x86 -LC:/sdl2_image/lib/x86 -lSDL2main -lSDL2 -lSDL2_image

all:
    $(CC) $(CFLAGS) main.c $(LIBS) -o application.exe

main.c

#include <stdio.h>
#include "SDL.h"
#include "SDL_image.h"


int main(int argc, char **argv)
{
    if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
    {
        SDL_Log("SDL fails to initialize video subsystem!\n%s", SDL_GetError());
        return -1;
    }
    else
        printf("SDL Video was initialized fine!\n");

    if((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG)
    {
        SDL_Log("SDL fails to initialize image handler!\n%s", IMG_GetError());
        return -1;
    }
    else
        printf("SDL Image was initialized fine!\n");

    return 0;
}

正如我之前所说,问题似乎出在 windows 库(或环境)上,这就是为什么我之前没有添加可重现的代码

【问题讨论】:

    标签: c sdl-2 sdl-image


    【解决方案1】:

    两天后我找到了解决办法。

    首先(但这不是我的问题)SDL Image 库不是那么“智能”,所以 SDL2_image.dll 库和使用的 libjpeg-9.dll、libpng16-16.dll 库很重要、libtiff-5.dll、libwebp-7.dll 和 zlib1.dll 存在。如果缺少所需的库之一,您将不会收到任何错误。

    我的环境有问题,在这台机器上我使用 Visual Studio 和 Eclipse。我犯了一个错误,我的 makefile 指向 Visual Studio SDL 库而不是 MinGW 库。

    我不知道为什么但是第一个可重现的例子也可以很好地解决这个错误(并且没有 -lmingw32),所以它指出了我的正确方法.

    我在 makefile 上做了这个更改,现在它可以工作了:

    CFLAGS = -IC:/sdl2_mingw/i686-w64-mingw32/include/SDL2 -IC:/sdl2_image_mingw/i686-w64-mingw32/include/SDL2 -O0 -ggdb
    LIBS = -lmingw32 -LC:/sdl2_mingw/i686-w64-mingw32/lib -LC:/sdl2_image_mingw/i686-w64-mingw32/lib -lSDL2main -lSDL2 -lSDL2_image
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      • 1970-01-01
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多