首页 > 解决方案 > 应用程序无法为 SDL2 应用程序正确启动 0xc00007b

问题描述

我正在使用 Visual Studio 在我的 x64 Windows 10 机器上构建 SDL 应用程序。

我已经按照本教程设置了包含/库/附加依赖项。

一切正常,直到我按照上面的示例添加 SDL_ttf 库作为指导,并将 SDL2_ttf.dll 粘贴到调试文件夹中。

我收到此错误:

“应用程序无法正确启动(0xc000007b)。单击确定关闭应用程序。*

如果我从文件夹中删除 SDL2_ttf.dll,我(仅)收到此错误:

我从此链接下载了 .dll(x64 版本) 。

我的 SDL2.dll 和 SDL2_image.dll(都是 x64)在我只使用这些库时运行我的可执行文件时正常工作。

这里有什么问题?为什么我会收到此错误?

附加信息

这是我正在运行的简单代码示例

//Using SDL and standard IO
#include <SDL.h>
#include <SDL_image.h>
#include <stdio.h>
#include <SDL_ttf.h>

//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

SDL_Window* gWindow = nullptr;
SDL_Surface* gScreenSurface = nullptr;

bool init()
{
    //Initialization flag
    bool success = true;
    
    IMG_Init(IMG_INIT_PNG);

    TTF_Init();

    //Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError());
        success = false;
    }
    
    else
    {
        //Create window
        gWindow = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
        if (gWindow == NULL)
        {
            printf("Window could not be created! SDL Error: %s\n", SDL_GetError());
            success = false;
        }
        else
        {
            //Initialize PNG loading
            int imgFlags = IMG_INIT_PNG;
            if (!(IMG_Init(imgFlags) & imgFlags))
            {
                printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
                success = false;
            }
            else
            {
                //Get window surface
                gScreenSurface = SDL_GetWindowSurface(gWindow);
            }
        }
    }

    return success;
}

int main(int argc, char* args[])
{
    init();

    //Destroy window
    SDL_DestroyWindow(gWindow);

    //Quit SDL subsystems
    SDL_Quit();

    return 0;
}

编辑:整理代码

编辑:我知道为什么我会看到这个问题。前几天我将一些库文件复制到了我的 MinGW 文件夹中,我可能已经覆盖了 SDL2 使用的一些重要的 dll 文件(在幕后)。如果我深入了解它,我会发布。同样,我可能会重新安装 MinGW,如果问题得到解决,我会发布更新。

编辑:我终于让它工作了。看起来我的 PATH 中某处有一个不适合我的 x64 应用程序的 dll,而且它不是我上面提到的 3 个 dll 中的任何一个。这就是我的工作文件夹的样子。

标签: windowsvisual-c++dll64-bitsdl-2

解决方案


使用 MinGW 安装管理器重新安装 MinGW 后,程序开始给出不同的错误,指示缺少哪个 dll。SDL 运行时库文件夹包含所有这些文件夹。我复制了它们的 x64 版本,应用程序运行成功。


推荐阅读