首页 > 解决方案 > CMake 和 MinGW w64 和 windows 系统库

问题描述

我开始学习 CMake。我想使用 MinGW w64 使用 SDL2 库构建我的应用程序。我生成 Makefile 并mingw32-make用于构建我的应用程序。但是我的应用程序在没有任何消息的情况下无法执行(我的操作系统是 Windows 10)。首先,我认为我的应用程序没有看到它的依赖项。我尝试使用DependencyWalker并找出下一步。我的应用看不到类似的库

API-MS-WIN-CORE-APIQUERY-L1-1-0.DLL API-MS-WIN-CORE-APPCOMPAT-L1-1-0.DLL API-MS-WIN-CORE-APPCOMPAT-L1-1-1.DLL API-MS-WIN-CORE-APPINIT-L1-1-0.DLL

和许多其他API-MS-WIN图书馆。C:\Windows\System32正如我所看到的,这个库位于C:\Windows\SysWOW64. 当我构建我的应用程序时,我链接了下一个库-lmingw32 -lSDL2main -lSDL -mwindows,并且链接没有任何错误,并且DependencyWalker对此并没有说什么不好。为什么我构建的应用程序没有看到 Windows 系统库?我的 PATH 环境有System32目录但没有SysWOW64. 也许这有问题?

更新

我尝试添加到 PATH 环境 SysWOW64 并没有帮助。添加DependecyWalker截图

更新 2

倒塌

标签: c++cmakesdl-2mingw-w64

解决方案


不好了!我犯了一个大错误。我的问题不是windows dll。我遵循指南。我没有编写创建窗口的部分代码。我的代码是

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

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

int main( int argc, char* args[] )
{
    //The window we'll be rendering to
    SDL_Window* window = NULL;

    //The surface contained by the window
    SDL_Surface* screenSurface = NULL;

    //Initialize SDL
    if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
    }
    else
    {
        //Get window surface
        screenSurface = SDL_GetWindowSurface( window );

        //Fill the surface white
        SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );

        //Update the surface
        SDL_UpdateWindowSurface( window );

        //Wait two seconds
        SDL_Delay( 2000 );
    }
}

从示例中编写代码时要小心:) 我通过添加我错过的部分来解决这个问题。现在我的程序运行良好。


推荐阅读