简体   繁体   English

是否可以将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?

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. 我的问题是,是否可以放置SDL .lib,dll和头文件,或可以执行的进程,所以当我创建C ++项目时,我可以键入#incldue <SDL2.h>来代替每次都要弄乱项目设置的麻烦。 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. 另外,我正在使用的IDE是在Windows 10上运行的visual studio 2017 RC。我也可以访问SDL源文件,因此如有必要,我可以对.c文件进行操作。

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. 请注意,所需的解决方案将允许程序员以包括#include <stdio.h>类的方式来包括sdl,无需进行额外的工作。

Although "making a project template is not a desirable solution to this question", I suggest, regarding Visual Studio 2017 Community, make it. 尽管“制作项目模板不是解决此问题的理想解决方案”,但我建议就Visual Studio 2017社区进行制作。 You can find instructions at ( wikihow.com/Set-Up-SDL-with-Visual-Studio-2017 ). 您可以在( wikihow.com/Set-Up-SDL-with-Visual-Studio-2017 )中找到说明。 Following is an overview. 以下是概述。

A. Downloading SDL and Creating Empty project. A.下载SDL并创建空项目。

A.1. A.1。 Create folder SDL, and put folder SDL2-2.0.8 in it. 创建文件夹SDL,并将文件夹SDL2-2.0.8放入其中。 In directory (disk) C:, create (by right click > New > Folder) new folder called SDL . 在目录(磁盘)C:中,创建(通过右键单击>新建>文件夹)名为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 . 点击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) . Windows下:单击第一个条目: SDL2-devel-2.0.8-VC.zip(Visual C ++ 32/64位) Drag (or, by right click, copy and paste) folder SDL2-2.0.8 from the window where it is downloaded, into folder C: > SDL. 将文件夹SDL2-2.0.8从下载窗口拖动(或通过右键单击复制和粘贴)到文件夹C:> SDL。

A.2. A2。 Create Empty project . 创建空项目 Open Visual Studio Community 2017, and create Empty project . 打开Visual Studio社区2017,并创建空项目 In the Name: text box, type SDLproject . 名称:文本框中,键入SDLproject After the Location text box, click Browse... and navigate C: > SDL. 在“ 位置”文本框后,单击“ 浏览...” ,然后导航到C:> SDL。 Click Select folder . 单击选择文件夹 The Location now is C:\\SDL. 现在的位置是C:\\ SDL。 Make sure the Create directory for solution box is not checked. 确保未选中为解决方案创建目录框。 Click [OK]. 点击[确定]。 Create source file with template C++ File (.cpp) . 使用模板C ++ File(.cpp)创建源文件。 Name it Source.cpp . 将其命名为Source.cpp The Location should be C:\\SDL\\SDLproject. 位置应为C:\\ SDL \\ SDLproject。

B. Installing SDL2-2.0.8 on Project B.在项目上安装SDL2-2.0.8

B.1. B.1。 Add the Include folder. 添加包含文件夹。 Right click on the name of your project, that is SDLproject (if you chose it), and select Properties. 右键单击您的项目名称,即SDLproject(如果选择了它),然后选择Properties。 Open the C/C++ dropdown menu. 打开C / C ++下拉菜单。 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. 在“ 选择目录”窗口中,导航至C:> SDL> SDL2-2.0.8,然后单击包含文件夹。 The Folder should be include . 文件夹包含 Click Select Folder on the Select Directory window and [OK] in the Additional Include Directories window. 在“ 选择目录”窗口中单击“ 选择文件夹 ”,然后在“ 附加包含目录”窗口中单击[确定]。

B.2. B.2。 Add the x86 folder. 添加x86文件夹。 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. 在“ 选择目录”窗口中,浏览C:> SDL> SDL2-2.0.8,然后双击lib文件夹,然后单击x86文件夹。 The Folder is x86 . 文件夹x86 Click Select folder on Select Directory window and [OK] on Additional Library Directories window. 单击“ 选择目录”窗口上的“ 选择文件夹” ,然后单击“ 其他库目录”窗口上的[确定]。

B.3. 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; 在“ 其他依赖关系”窗口中,复制并粘贴SDL2.lib; SDL2main.lib in the top-most text box. 最顶部的文本框中的SDL2main.lib 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. 单击向下箭头,然后从下拉菜单中选择Console(/ SUBSYSTEM:CONSOLE)。 Click [Apply], then [OK] on the Property Pages window. 单击[应用],然后在“ 属性页”窗口上单击[确定]。

B.4. 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. 单击向下箭头,然后从下拉菜单中选择Console(/ SUBSYSTEM:CONSOLE)。 Click [Apply], then [OK] on the Property Pages window. 单击[应用],然后在“ 属性页”窗口上单击[确定]。

B.5. B.5。 Copy the SDL2.dll file from x86 to your main project file. 将SDL2.dll文件从x86复制到主项目文件。 Navigate C: > SDL > SDL2-2.0.8 > lib > x86 in file explorer. 在文件浏览器中浏览C:> SDL> SDL2-2.0.8> lib> x86。 In x86 folder click SDL2.dll file > right-click > Copy. 在x86文件夹中,单击SDL2.dll文件>右键单击>复制。 Navigate to your C: > SDL > SDLproject. 浏览至C:> SDL> SDLproject。 Right-click an empty area in SDLproject folder, and select Paste . 右键单击SDLproject文件夹中的空白区域,然后选择粘贴 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. 现在, SDL2.dll文件应该与Source.cpp文件以及Visual Studio创建的其他一些文件一起位于项目目录中。

Now you can compile and run your SDL program. 现在,您可以编译并运行SDL程序。

C. Creating project with SDL project template. C.使用SDL项目模板创建项目。

C.1. C.1。 Create project template. 创建项目模板。 By Windows's Paint program create icon with file name SDL . 通过Windows的Paint程序,创建文件名为SDL的图标。 Go to Visual Studio and open SDLproject . 转到Visual Studio并打开SDLproject On VS menu click Project > Export Template.... On Export template Wizard check Project Template... , if it's not checked. 在VS菜单上,单击“项目”>“导出模板...”。在“ 导出模板向导”上,检查“ 项目模板...” (如果未选中)。 Click Next > . 单击下一步> On Select Template Options , Template name:'s text field, type SDL . 在“ 选择模板选项” ,“模板名称:”的文本字段上,输入SDL Click the upper [Browse...] (that one next to Icon Image: text field). 单击上方的[浏览...](“ 图标图像:”文本字段旁边的那个)。 Navigate to folder Images . 导航到“ 图像”文件夹。 Click image SDL . 单击图像SDL Click [Open]. 点击[打开]。 Now path of Icon Image: is ending with \\SDL.png. 现在,“ 图标图像: ”的路径以\\ SDL.png结尾。 Click [Finish]. 点击[完成]。

C.2. C.2。 Create project with SDL project template. 使用SDL项目模板创建项目。

C.2.1. C.2.1。 On VS click File > New > Project.... On New Project window, click template: SDL . 在VS上,单击“文件”>“新建”>“项目...”。在“ 新项目”窗口上,单击模板: SDL In Name: 's text field, type: SDLproject-1 . 名称:的文本字段中,输入: SDLproject-1 Location is C:\\SDL. 位置是C:\\ SDL。 Be sure Create directory for solution is unchecked. 确保未选中为解决方案创建目录 Click [OK]. 点击[确定]。

C.2.2. C.2.2。 On Solution Explorer , double click Source Files . 解决方案资源管理器上 ,双击“ 源文件” Click Source.cpp > right click > click Exclude From Project . 单击Source.cpp >右键单击>单击“ 从项目中排除”

C.2.3. C.2.3。 Again right click Source Files > Add > New Item.... On Add New Item - SDLproject-1 window, click C++ File (.cpp) . 再次右键单击Source Files> Add> New Item...。在Add New Item-SDLproject-1窗口中,单击C ++ File(.cpp) In Name: 's text field, type: Source-1.cpp . 名称:的文本字段中,输入: Source-1.cpp The Location is C:\\SDL\\SDLproject-1. 位置为C:\\ SDL \\ SDLproject-1。 Click Add . 点击添加 Now on Solution Explore , below Source Files , you have Source-1.cpp file only. 现在,在“ 解决方案资源管理器”的“ 源文件”下 ,您只有Source-1.cpp文件。

C.2.4. C.2.4。 Navigate C: > SDL > SDLproject > click file SDL2.dll > right click > click Copy. 浏览C:> SDL> SDLproject>单击文件SDL2.dll>右键单击>单击复制。 Now navigate C: > SDL > SDLproject-1 > click on empty area > right click > click Paste. 现在导航C:> SDL> SDLproject-1>单击空白区域>右键单击>单击粘贴。 File SDL2.dll is in folder SDLproject-1 among Source-1.cpp and other 4 files. 文件SDL2.dllSource-1.cpp和其他4个文件中的SDLproject-1文件夹中。

C.2.5. C.2.5。 Now you can compile your SDL project. 现在,您可以编译您的SDL项目。 On window This project is out of date: , below question Would you like to build it? 在窗口上该项目已过时: ,在问题下方, 您要构建它吗? click [Yes]. 点击[是]。

D. Remark: Creating project with SDL-project-template is as creating ordinary C++ project, but two more steps: D.备注:使用SDL-project-template创建项目就像创建普通C ++项目一样,但是还有两个步骤:

D.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). 在模板项目(SDLproject,在该示例)的解决方案管理器源文件 ,源文件(Source.cpp在上面的例子中)应当从新的项目被排除(SDLproject-1的示例中)。

D.2. D.2。 File SDL2.dll should be copied from template project and pasted in new project. 文件SDL2.dll应该从模板项目复制并粘贴到新项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM