是否可以将 SDL .lib、.dll 和头文件放在某处,以便我只需键入 #include <SDL2.h>在 Visual Studio 2017 RC 项目中? [英] Is it possible to put the SDL .lib, .dll, and header files somewhere so I can just type #include <SDL2.h> in a visual studio 2017 RC project?

查看:31
本文介绍了是否可以将 SDL .lib、.dll 和头文件放在某处,以便我只需键入 #include <SDL2.h>在 Visual Studio 2017 RC 项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,有没有我可以放置 SDL .lib、dll 和头文件的地方,或者我可以做的进程,所以当我创建 C++ 项目时,我只需键入 #incldue<SDL2.h> 而不必每次都搞乱项目设置.制作项目模板也不是解决这个问题的理想方法.此外,我使用的 IDE 是在 Windows 10 上运行的 Visual Studio 2017 RC.我还可以访问 SDL 源文件,因此我可以在必要时对 .c 文件进行处理.

My question is, is there a place(s) I can put the SDL .lib, dll, and header files, or process I can do, so when I create a C++ project I can just type #incldue <SDL2.h> instead of having to mess about with the project settings every time. Also making a project template is not a desirable solution to this question. Also, the IDE I am using is visual studio 2017 RC, running on windows 10. I also have access to the SDL source file so I could do something with the .c files if necessary.

请注意,所需的解决方案将允许程序员以与包含 #include <stdio.h> 之类的内容相同的方式包含 sdl,无需额外工作.

Note that the desired solution would allow the programmer to include sdl in the same way they would include something like #include <stdio.h>, no extra work.

推荐答案

虽然制作项目模板不是解决这个问题的理想方法",但我建议,关于 Visual Studio 2017 社区,制作它.您可以在 (wikihow.com/Set-Up-SDL-with-Visual-Studio-2017).以下是概览.

Although "making a project template is not a desirable solution to this question", I suggest, regarding Visual Studio 2017 Community, make it. You can find instructions at (wikihow.com/Set-Up-SDL-with-Visual-Studio-2017). Following is an overview.

A.下载 SDL 并创建空项目.

A.1.创建文件夹SDL,并将文件夹SDL2-2.0.8放入其中.在目录(磁盘)C:中,创建(通过右键单击>新建>文件夹)名为的新文件夹SDL.如果需要,您可以选择另一个目录或文件夹,并为新文件夹选择另一个名称.点击 https://www.libsdl.org/download-2.0.php.滚动到页面底部并找到开发库.在 Windows: 下,单击第一个条目:SDL2-devel-2.0.8-VC.zip (Visual C++ 32/64-bit).将文件夹 SDL2-2.0.8 从下载的窗口中拖(或通过右键单击、复制和粘贴)到文件夹 C:> SDL.

A.1. Create folder SDL, and put folder SDL2-2.0.8 in it. In directory (disk) C:, create (by right click > New > Folder) new folder called SDL. If desired, you can choose another directory or folder, and another name for the new folder. Click at https://www.libsdl.org/download-2.0.php. Scroll to the bottom of the page and find Development Libraries. Under Windows: click the first entry: SDL2-devel-2.0.8-VC.zip (Visual C++ 32/64-bit). Drag (or, by right click, copy and paste) folder SDL2-2.0.8 from the window where it is downloaded, into folder C: > SDL.

A.2.创建空项目.打开 Visual Studio Community 2017,并创建空项目.在名称: 文本框中,键入 SDLproject.在 Location 文本框之后,单击 Browse... 并导航 C: > SDL.点击选择文件夹.位置现在是 C:\SDL.确保 为解决方案创建目录 框未选中.单击 [确定].使用模板 C++ 文件 (.cpp) 创建源文件.将其命名为 Source.cpp.位置应该是 C:\SDL\SDLproject.

A.2. Create Empty project. Open Visual Studio Community 2017, and create Empty project. In the Name: text box, type SDLproject. After the Location text box, click Browse... and navigate C: > SDL. Click Select folder. The Location now is C:\SDL. Make sure the Create directory for solution box is not checked. Click [OK]. Create source file with template C++ File (.cpp). Name it Source.cpp. The Location should be C:\SDL\SDLproject.

B.在项目上安装 SDL2-2.0.8

B.1.添加 Include 文件夹. 右键单击​​您的项目名称,即 SDLproject(如果您选择了它),然后选择属性.打开 C/C++ 下拉菜单.单击常规 > 其他包含目录 > 字段右侧的向下箭头 > 编辑... 在下拉菜单中.在附加包含目录"窗口的顶部,单击棕色文件夹图标(第一个图标).单击创建的文本框旁边的三个点 (...).在 Select Directory 窗口中,导航 C: > SDL > SDL2-2.0.8,然后单击 include 文件夹.文件夹应该是include.在选择目录窗口中点击选择文件夹,然后在附加包含目录窗口中点击[确定].

B.1. Add the Include folder. Right click on the name of your project, that is SDLproject (if you chose it), and select Properties. Open the C/C++ dropdown menu. Click General > Additional Include Directories > down arrow at the right of the field > Edit... in the drop down menu. At the top of the Additional Include Directories window, click the brown folder icon (the first icon). Click the three dots (...) next to the text box that is created. In the Select Directory window, navigate C: > SDL > SDL2-2.0.8, and click include folder. The Folder should be include. Click Select Folder on the Select Directory window and [OK] in the Additional Include Directories window.

B.2.添加 x86 文件夹. 打开 Linker 下拉菜单,然后单击 General.单击其他库目录条目,然后单击该字段右侧的向下箭头.点击下拉菜单中的编辑....在其他库目录窗口顶部,单击棕色文件夹图标.然后单击创建的文本框旁边的三个点.在 Select Directory 窗口中,导航 C: > SDL > SDL2-2.0.8,然后双击 lib 文件夹,然后单击 x86文件夹.文件夹x86.在选择目录窗口中点击选择文件夹,在附加库目录窗口中点击[确定].

B.2. Add the x86 folder. Open the Linker dropdown menu, and click General. Click Additional Library Directories entry, and click the down arrow at the right of the field. Click Edit... in the dropdown menu. At the top of the Additional Library Directories window, click the brown folder icon. Then click the three dots next to the text box that is created. In the Select Directory window, navigate C: > SDL > SDL2-2.0.8, and then double click lib folder, followed by clicking x86 folder. The Folder is x86. Click Select folder on Select Directory window and [OK] on Additional Library Directories window.

B.3.添加两个库文件.链接器下拉菜单中,单击输入.单击附加依赖项条目 > 字段右侧的向下箭头 > 下拉菜单中的编辑....在 Additional Dependencies 窗口中复制并粘贴 SDL2.lib;SDL2main.lib 在最顶部的文本框中.在附加依赖项窗口中单击[[确定].在 Linker 下拉菜单中,单击系统 > 子系统.单击向下箭头并从下拉菜单中选择 Console(/SUBSYSTEM:CONSOLE).在属性页窗口中单击[应用],然后单击[确定].

B.3. Add the two library files. In the Linker dropdown menu, click Input. Click the Additional Dependencies entry > the down arrow at the right of the field > Edit... in the dropdown menu. In Additional Dependencies window copy and paste SDL2.lib; SDL2main.lib in the top-most text box. Click[ [OK] in the Additional Dependencies window. In the Linker dropdown menu, click System > SubSystem. Click the down arrow and select Console(/SUBSYSTEM:CONSOLE) from the dropdown menu. Click [Apply], then [OK] on the Property Pages window.

B.4.将链接器子系统配置为控制台.链接器 下拉菜单中,单击系统 > 子系统.单击向下箭头并从下拉菜单中选择 Console(/SUBSYSTEM:CONSOLE).在属性页窗口中点击[应用],然后点击[确定].

B.4. Configure the linker subsystem to console. In the Linker dropdown menu, click System > SubSystem. Click the down arrow and select Console(/SUBSYSTEM:CONSOLE) from the dropdown menu. Click [Apply], then [OK] on the Property Pages window.

B.5.将 SDL2.dll 文件从 x86 复制到您的主项目文件. 在文件资源管理器中导航 C: > SDL > SDL2-2.0.8 > lib > x86.在 x86 文件夹中单击 SDL2.dll 文件 > 右键单击​​ > 复制.导航到您的 C: > SDL > SDL 项目.右键单击SDLproject 文件夹中的空白区域,然后选择粘贴.SDL2.dll 文件现在应该与您的 Source.cpp 文件和一些其他由 Visual Studio 创建的文件一起位于您的项目目录中.

B.5. Copy the SDL2.dll file from x86 to your main project file. Navigate C: > SDL > SDL2-2.0.8 > lib > x86 in file explorer. In x86 folder click SDL2.dll file > right-click > Copy. Navigate to your C: > SDL > SDLproject. Right-click an empty area in SDLproject folder, and select Paste. The SDL2.dll file should now be in your project directory along with your Source.cpp file and a few other files created by Visual Studio.

现在您可以编译和运行您的 SDL 程序了.

Now you can compile and run your SDL program.

C.使用 SDL 项目模板创建项目.

C.1.创建项目模板.通过Windows 的Paint 程序创建文件名为SDL 的图标.转到 Visual Studio 并打开 SDLproject.在 V.S.菜单单击项目> 导出模板....在导出模板 向导中检查项目模板...,如果它没有被选中.单击下一步>.在选择模板选项,模板名称:的文本字段中,输入SDL.单击上方的 [浏览...](图标图像: 文本字段旁边的那个).导航到文件夹 Images.单击图像SDL.单击 [打开].现在 Icon Image: 的路径以 \SDL.png 结尾.点击【完成】.

C.1. Create project template. By Windows's Paint program create icon with file name SDL. Go to Visual Studio and open SDLproject. On V.S. menu click Project > Export Template.... On Export template Wizard check Project Template..., if it's not checked. Click Next >. On Select Template Options, Template name:'s text field, type SDL. Click the upper [Browse...] (that one next to Icon Image: text field). Navigate to folder Images. Click image SDL. Click [Open]. Now path of Icon Image: is ending with \SDL.png. Click [Finish].

C.2.使用 SDL 项目模板创建项目.

C.2.1. 在 V.S.单击文件 > 新建 > 项目....在 新建项目 窗口中,单击模板:SDL.在名称:的文本字段中,输入:SDLproject-1.位置是 C:\SDL.确保 为解决方案创建目录 未选中.点击【确定】.

C.2.1. On V.S. click File > New > Project.... On New Project window, click template: SDL. In Name:'s text field, type: SDLproject-1. Location is C:\SDL. Be sure Create directory for solution is unchecked. Click [OK].

C.2.2.解决方案资源管理器上,双击源文件.单击Source.cpp > 右键单击​​> 单击从项目中排除.

C.2.2. On Solution Explorer, double click Source Files. Click Source.cpp > right click > click Exclude From Project.

C.2.3. 再次右键单击 Source Files > Add > New Item.... 在 Add New Item - SDLproject-1 窗口中,单击 C++文件 (.cpp).在名称: 的文本字段中,输入:Source-1.cpp.位置是 C:\SDL\SDLproject-1.点击添加.现在在解决方案探索中,在源文件下面,您只有Source-1.cpp文件.

C.2.3. Again right click Source Files > Add > New Item.... On Add New Item - SDLproject-1 window, click C++ File (.cpp). In Name:'s text field, type: Source-1.cpp. The Location is C:\SDL\SDLproject-1. Click Add. Now on Solution Explore, below Source Files, you have Source-1.cpp file only.

C.2.4. 导航 C: > SDL > SDLproject > 单击文件 SDL2.dll > 右键单击​​ > 单击复制.现在导航 C: > SDL > SDLproject-1 > 单击空白区域 > 右键单击​​ > 单击粘贴.文件SDL2.dllSource-1.cpp和其他4个文件中的SDLproject-1文件夹中.

C.2.4. Navigate C: > SDL > SDLproject > click file SDL2.dll > right click > click Copy. Now navigate C: > SDL > SDLproject-1 > click on empty area > right click > click Paste. File SDL2.dll is in folder SDLproject-1 among Source-1.cpp and other 4 files.

C.2.5. 现在您可以编译您的 SDL 项目.在窗口此项目已过时:,下面的问题您要构建它吗?单击 [是].

C.2.5. Now you can compile your SDL project. On window This project is out of date:, below question Would you like to build it? click [Yes].

D.备注:用SDL-project-template创建项目与创建普通C++项目一样,但多了两步:

D. Remark: Creating project with SDL-project-template is as creating ordinary C++ project, but two more steps:

D.1.解决方案资源管理器中,源文件,源文件(Source.cpp在上面的示例)的模板项目(在示例中为SDLproject)应从新项目(在示例中为SDLproject-1)中排除.

D.1. In Solution Explorer, Source Files, source file (Source.cpp in the example above) of template project (SDLproject, in the example) should be excluded from new project (SDLproject-1 in example).

D.2. 文件 SDL2.dll 应该从模板项目中复制并粘贴到新项目中.

D.2. File SDL2.dll should be copied from template project and pasted in new project.

这篇关于是否可以将 SDL .lib、.dll 和头文件放在某处,以便我只需键入 #include &lt;SDL2.h&gt;在 Visual Studio 2017 RC 项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆