该应用程序无法为SDL2应用程序正确启动0xc00007b 这是我正在运行的简单代码示例

问题描述

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

我已经按照this教程设置了include / library / additional依赖项。

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

我收到此错误

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

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

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

我的SDL2.dll和SDL2_image.dll(均为x64)正常运行,因为当我仅使用那些库时,我的可执行文件就会运行。

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

其他信息

  • 我检查了system32文件夹(以及整个Windows父文件夹),但没有在其中找到SDL_ttf.dll。

  • 此外,这是我的调试文件夹的样子:

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

//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,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中的任何一个。这就是我的工作文件夹。

解决方法

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