FROM: http://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/msvc2019/index.php

Setting up SDL 2 on Visual Studio 2019 Community

Last Updated 7/20/20
1)First thing you need to do is download SDL 2 headers and binaries. You will find them on the SDL website, specifically on this page.

You'll want to download the Visual C++ development libraries.

Open the zip archive and there should be a folder called SDL2-2.something.something. Copy the contents of the folder and put it anywhere you'd like. I recommend putting it in a folder that you dedicate to holding all your development libraries for Visual C++. For these tutorials I'm putting them in a directory I created called C:\vclib

2)Start up Visual Studio and create a new empty C++ project.

Give your project/solution whatever name you'd like and place it where ever you'd like.

3)Go download the source for lesson 01 and extract the source file. Right click on the source files folder in your solution, and then add the source file you downloaded.

4)Now, if your default build setting is Debug x86, you may need to change it:

For the rest of this tutorial, we will be assuming you are building for Debug x64 so make sure your configuation is set to Debug x64. Because libraries are different per configuation, you will need to add SDL to every configuation you plan on using. So if you want to build for Release x64 or Debug x86, you will need to add SDL2 to each configuation.

5)Build your solution and you should get the following error:

Cannot open include file: 'SDL.h': No such file or directory

This means Visual C++ cannot find the SDL header files and you need to add the SDL include folder to the Visual C++ include directories.

Go to project properties:

Go to Configuration Properties -> VC++ Directories -> Include Directories -> Edit.

And then add the include directory from the SDL development folder we extracted.

6)Try to build your solution again and you should get a bunch of errors including:

unresolved external symbol SDL_GetError referenced in function SDL_main

The header file tells the compiler what the SDL functions are, not where to find them. The library file tells the compiler where they are and we need to tell it to use the SDL library file. Go to Configuration Properties -> Linker -> Additional Dependencies -> Edit.

Now add

SDL2.lib; SDL2main.lib;

7)Try to build your solution again and you should get a new error:

cannot open file 'SDL2.lib'

While we did tell Visual C++ to use the SDL library files, we didn't tell it where to find it. Add the library directory like you did the include directory

Make sure to add the library that matches your build configuation. If your building for x64, make sure to use the x64 library.

8)Build and your application should build, but try to run it and you'll get this error:

The code execution cannot proceed because SDL2.dll was not found.

This is because your application needs SDL2.dll to run but can't find it. Windows uses environment variables to define where to look for dll files. To edit the PATH environment variable, go into Windows Settings and search for edit the system environment variables:

Click environment variables and under System Variables select Path and click Edit

Then click new, then browse to add the lib directory for your build configuation:

Restart Visual Studio so Visual C++ can get the updated path variable, start your program and it should run.

Now that you have SDL 2 compiling, it's time to go onto part 2 of the tutorial.

【转】Setting up SDL 2 on Visual Studio 2019 Community的更多相关文章

  1. 【转】Setting up SDL 2 on Visual Studio 2010 Ultimate

    from: Lazy Foo'Productions - Setting up SDL 2 on Visual Studio 2010 Ultimate 1)First thing you need ...

  2. 【转】Setting up SDL Extension Libraries on Visual Studio 2019 Community

    FROM:http://lazyfoo.net/tutorials/SDL/06_extension_libraries_and_loading_other_image_formats/windows ...

  3. 解决VS命令提示符 “Setting environment for using Microsoft Visual Studio. 此时不应有“系列错误

    一.起因 近期在玩Boost库.当然首先是要进行Boost库的安装和配置.于是浅墨Google了一下boost库的安装配置攻略.下载了最新版1.55的boost库.就愉悦地開始进行配置了. 当进行到第 ...

  4. Visual Studio 2019 发布活动 - 2019 年 4 月 2 日

    Visual Studio 2019 发布活动 2019 年 4 月 2 日,星期二 | 上午 9:00 (PT) 围观: https://visualstudio.microsoft.com/zh- ...

  5. Visual Studio 2019 正式发布,重磅更新,支持live share

    如约而至,微软已于今天推出 Visual Studio 2019 正式版,一同发布的还有 Visual Studio 2019 for Mac. Visual Studio 2019 下载地址:htt ...

  6. “宇宙最强” IDE,Visual Studio 2019 正式发布

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 本文由葡萄城翻译并发布 今天凌晨Visual Studio 2019已经正式发布,现在已经可以下载了.使用V ...

  7. Visual Studio 2019 使用 Live Share

    一.前言 Visual Studio 2019 在今天发布(北京时间)了,这次带来了一个比较有趣的 Live Share 功能,使用它可以进行更好的协作开发.主要功能: 更多资料可看官方介绍: Vis ...

  8. Visual Studio 2019 正式版 更新内容

    大早上更新了Visual Studio 2019, 试用一下 一.界面改变 1.项目创建界面 首先启动界面改变就不说了,创建项目的界面做了较大改变,感觉在向vs for mac 靠拢 ,而后者感觉像x ...

  9. Making every developer more productive with Visual Studio 2019

    Today, in the Microsoft Connect(); 2018 keynote, Scott Guthrie announced the availability of Visual ...

随机推荐

  1. Oracle复习(复习精简版v1.0)

    自己没记不住的,超基础Oracle知识,新手可以看一下. 大多数例子是用scott用户中的emp表完成 排序:order by 列名    desc是降序,默认是升序: update 表名 set 列 ...

  2. Processing 网格纹理制作(棋盘格)使用pixel() set()像素点绘制方式

    接上 我们趁热打铁,紧接上一回的棋盘格绘制,来挖掘一些不同绘制思路,使用pixel()函数来绘画.这是一个以每个像素点作为对象来绘制的思路,而不是以图形的方式来填充.这就改变了绘画思路.实际上,Pro ...

  3. Servlet3.x部署描述符

    简介 web.xml即部署描述符,位于WEB-INF目录下.在Servlet3以上版本有提供了注解的方式部署Servlet,因此web.xml是可选的.web.xml大概框架如下: <?xml ...

  4. 微信小程序-简介

    微信小程序定位 1. 不需要下载安装即可使用 2. 用户用完即走,不用关系是否安装太多应用 3. 应用无处不在,随时可用 # 不要安装可使用是个伪命题,因为小程序的安装包小于1M,下载安装到使用的过程 ...

  5. 用ThreadLocal来优化下代码吧

    最近接手了一个老项目,看到一个很有意思的现象. 这个项目中大量的方法入参都会带上user信息,比如这样 它的意图是希望在方法内使用user的信息,但是如此大范围的传递用户信息,第一感觉就是不优雅.那有 ...

  6. MyBatis 进阶,MyBatis-Plus!(基于 Springboot 演示)

    这一篇从一个入门的基本体验介绍,再到对于 CRUD 的一个详细介绍,在介绍过程中将涉及到的一些问题,例如逐渐策略,自动填充,乐观锁等内容说了一下,只选了一些重要的内容,还有一些没提及到,具体可以参考官 ...

  7. Java知识系统回顾整理01基础01第一个程序03Eclipse下载安装

    Eclipse是最流行的java 集成开发环境IDE(Integrated Development Environment) 下载安装Eclipse两种方式 一.方式1:Eclipse官网下载安装 链 ...

  8. python 给IDLE添加行号

    [LineNumbers] enable=1 enable_editor=1 enable_shell=1 visible=1 [LineNumbers_cfgBindings] linenumber ...

  9. JVM系列【4】内存模型

    JVM系列笔记目录 虚拟机的基础概念 class文件结构 class文件加载过程 jvm内存模型 JVM常用指令 GC与调优 硬件层数据一致性 - 存储器层次结构 从L6-L0 空间由大变小,速度由慢 ...

  10. ANOI 2009 【同类分布】

    好累啊啊啊~~~~~~,刷了一天的题了,嗯,再写两篇题解我就去颓Slay... 思路分析: 刚刚我们讲了数位DP,现在就感受一下吧.(其实我也就只敢做做安徽的题,四川的数位DP想都不敢想) 嗯好,我们 ...