VS2019创建SDL2工程,以及找不到SDL2.dll

1、创建一个空白工程。

2、将下载好的SDL2复制到工程根目录。

3、配置SDL2路径。

用IAR或者KEIL等开发过的朋友,都知道,需要2-3步。分别为添加头文件路径;再工程中添加用得到的文件(即添加.c文件);如果有需要在IDE配置中添加宏定义。

VS2019中的配置如下

1)添加头文件

第一步之后选最下面的调试属性。

2)添加".c文件"(SDL2库文件)

如上图所示,添加就行,不需要像KEIL一样处理。

3) 添加宏定义 

输入SDL2.LIB、SDL2main.lib就行。 

 

4、将创建一个main.cpp到工程根目录,并填入以下内容:

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


int main(int argc, char* args[])
{
    //启动SDL
    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Window* window;                    // Declare a pointer
    window = SDL_CreateWindow(
        "HELLO SDL2",                  // window title
        SDL_WINDOWPOS_UNDEFINED,           // initial x position
        SDL_WINDOWPOS_UNDEFINED,           // initial y position
        480,                               // width, in pixels
        320,                               // height, in pixels
        SDL_WINDOW_OPENGL                  // flags - see below
    );

    // Check that the window was successfully created
    if (window == NULL) {
        // In the case that the window could not be made...
        printf("Could not create window: %s\n", SDL_GetError());
        return 1;
    }

    // The window is open: could enter program loop here (see SDL_PollEvent())

    //按任意键退出
    system("pause");
    //退出SDL 
    SDL_Quit();

    return 0;
}

5、点击运行出错

需要将SDL2.dll粘贴到main.cpp相同目录下。

6、最终运行成功

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值