Allegro 5 Visual Studio 2015吗? [英] Allegro 5 Visual Studio 2015?

查看:110
本文介绍了Allegro 5 Visual Studio 2015吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了一段时间,许多资料来源建议将Allegro用作C ++的2d库。但是,在这个时代,我发现将Allegro 5的库应用于Visual Studio 15并没有学费。



这是否可行,或者我是否必须降级到Visual Studio 2010 ?

解决方案

截至2016年编辑:
目前是Allegro 5的首选安装方法(当前版本为5.2.1)在Visual Studio上是通过NuGet包进行的。链接为



在这里,我们告诉Visual Studio如何使用Allegro。打开Visual Studio并创建一个新的C ++项目/打开您要在其中使用Allegro的项目。打开该项目后,在解决方案资源管理器上右键单击其名称,然后打开 Properties ,然后:


  1. 在顶部,显示类似 Configuration:Active(Debug)的内容,选择 All Configurations

  2. 在左侧菜单中选择 C / C ++->常规。在此配置页上,选择其他包含目录,然后对其进行编辑以在其文本字段中包含 C:\allegro\include\

  3. 在左侧菜单中选择链接器->常规。在此配置页面上,选择其他库目录,然后对其进行编辑,以在其文本字段中包含 C:\allegro\lib\ 。 / li>
  4. 单击底部的应用,但尚未关闭窗口。

  5. 返回顶部,选择调试配置。

  6. 在左侧菜单上选择链接器->输入。在此配置页面上,选择其他依赖项并对其进行编辑,以在其文本字段中包含 allegro_monolith-debug.lib

  7. (可选)在左侧菜单上选择 Linker-> System 。在此配置页面上,选择 SubSystem ,然后从下拉框中将其更改为Console。这将在Debug模式下为您提供一个工作的终端窗口,您可以在其中编写... err ... debug内容;)

  8. 单击底部的Apply,但不要关闭

  9. 返回顶部,选择发布配置。

  10. 在左侧菜单中,选择 Linker-> Input 。在此配置页面上,选择其他依赖项并对其进行编辑,以在其文本字段中包含 allegro_monolith.lib

  11. (可选)在左侧菜单上选择 Linker-> System 。在此配置页面上,选择 SubSystem ,然后从下拉框中将其更改为Windows。

  12. 单击应用,然后单击确定,这将关闭项目的属性页,并应为Allegro做准备。
  13. li>



步骤4



这是我们测试所有工作原理的部分... (或者不,请参见出现错误后的下一步)



创建一个* .cpp文件或使用主函数所在的文件并将其更改为以下小型测试程序: (我放弃了对它的所有权利并将其置于公共领域)

  #include allegro5\allegro5.h 
#include< iostream>

int main(int argc,char ** argv)
{
al_init();

ALLEGRO_DISPLAY *显示= nullptr;
al_set_app_name(来自Allegro 5.1的Hello World!);
display = al_create_display(640,480);
if(display == nullptr)
{
std :: cerr<< 嗯,有些东西不起作用...<< std :: endl;
al_rest(5.0);
返回EXIT_FAILURE;
}

al_clear_to_color(al_map_rgb(255,255,255));
al_flip_display();
al_rest(5.0);
返回0;
}

如果在编译和运行后出现空白窗口,该窗口在5秒后关闭,则快板准备好了!如果没有,请发布您的错误消息,然后我会看看发生了什么。



步骤5



我们在执行时解决了丢失的DLL错误的地方...



因此程序应该已经正确编译,Visual Studio现在将尝试运行它。启动时,可能会出现以下内容:





解决方案是将 allegro_monolith-debug-5.1.dll 文件复制到项目根目录的Debug文件夹中,以便它位于程序的.exe文件旁边。同样,在Release文件夹中,您必须复制 allegro_monolith-5.1.dll 在该文件夹的可执行文件旁边。这两个文件都应位于下载档案的 allegro\bin\ 目录中。请记住,您可能会需要我说过的另一个dll,但也应将其包含在从 Gna!下载的文件中。



注意:我链接到的软件包仅提供基本的Allegro 5库,而不提供其依赖项。可能发行二进制文件中包含了它们,但是Debug版本可能需要您手动链接它们。它们位于此处。选择 1.2.0 软件包以获取最新版本的allegro 5.1.12。


I've been browsing for a while and a lot of sources recommend using Allegro as a first time 2d Library for C++; however, in this day and age i have found no tuition on applying Allegro 5's libraries to Visual Studio 15.

Is this possible or am I having to downgrade to Visual Studio 2010?

解决方案

Edit as of 2016: Currently the preferred method of installation of Allegro 5 (which is at version 5.2.1 at the moment) on Visual Studio is through NuGet Packages. The link is here. This is the easiest and quickest method to get Allegro, and is the one everyone should use. Tested on Visual Studio Community 2015.


Apparently the guides on the net seem to be outdated or seem to forget that the Official Site has recent and modern binaries ready for download. So here is how to setup Allegro:

Assumptions

First thing first, I will be using the Unstable branch, 5.1, since it is the one that has the new binaries. And Second, I will be using Visual Studio 2013 but it should be exactly the same for Visual Studio 2015 (Step 1 below has the only difference in the process you might encounter).

Step 1

We will download Allegro 5 direct from the Gna! repository. Here you select the file depending on what you have and what you want to do.

This directory has 4 files, in my case, I will download allegro-msvc2013-x86-5.1.12.zip and you will download allegro-msvc2015-x86-5.1.12.zip. Select the x64 version only if you know what you are doing.

Step 2

When it finishes downloading, extract the contents somewhere that is easy to reach and that you will not move, such as the root of your hardrive or inside Documents. I'll go with the root, usually drive C:. After the extraction, you should have a folder in C:\allegro\ with the following content:

allegro\
 |-bin\
 |-include\
 |-lib\

It is important you remember where you extracted the files as setting the environment correctly depends on its ability to locate this path.

Step 3

Here we tell Visual Studio how to use Allegro. Open Visual Studio and create a new C++project/open the project you want Allegro to be used in. With the project open, right click its name on the solution explorer and open Properties then:

  1. At the top, where it says something like Configuration: Active(Debug), select All Configurations.
  2. On the left menu select C/C++ -> General. On this configuration page, select Additional Include Directories and edit it to containC:\allegro\include\ in its text field.
  3. On the left menu select Linker -> General. On this configuration page, select Additional Library Directories and edit it to contain C:\allegro\lib\ in its text field.
  4. Click on Apply at the bottom, but don´t close the window yet.
  5. Back at the top, select the Debug configuration.
  6. On the left menu select Linker -> Input. On this configuration page, select Additional Dependencies and edit it to contain allegro_monolith-debug.lib in its text field.
  7. (Optional)On the left menu select Linker -> System. On this configuration page, select SubSystem and change it to Console from the drop-down box. This will give you a working terminal window in Debug mode to which you can write ...err... debug stuff ;)
  8. Click on Apply at the bottom, but don´t close the window yet.
  9. Back at the top, select the Release configuration.
  10. On the left menu select Linker -> Input. On this configuration page, select Additional Dependencies and edit it to contain allegro_monolith.lib in its text field.
  11. (Optional)On the left menu select Linker -> System. On this configuration page, select SubSystem and change it to Windows from the drop-down box. This will prevent the Terminal window to appear on Release versions of your program.
  12. Click on Apply then OK, this will close the Property Pages of the project and should prepare it for Allegro.

Step 4

This is the part where we test everything worked...(or not, see next step after error)

Create a *.cpp file or use the one where your main function is located and change it to this small test program: (I give away all my rights to it and place it under public domain)

#include "allegro5\allegro5.h"
#include <iostream>

int main(int argc, char** argv)
{
    al_init();

    ALLEGRO_DISPLAY *display = nullptr;
    al_set_app_name("Hello World from Allegro 5.1!");
    display = al_create_display(640, 480);
    if (display == nullptr)
    {
        std::cerr << "Well, something is not working..." << std::endl;
        al_rest(5.0);
        return EXIT_FAILURE;
    }

    al_clear_to_color(al_map_rgb(255, 255, 255));
    al_flip_display();
    al_rest(5.0);
    return 0;
}

If after compiling and running you get a blank window that closes in 5 seconds then Allegro is ready! If not, post your error message and I'll take a look at what happened.

Step 5

Where we solve the missing DLL error upon execution...

So the program should have compiled correctly and Visual Studio will now attempt to run it. Upon starting, the following might appear:

The solution is to copy on the Debug folder on the root of your project the allegro_monolith-debug-5.1.dll file, so that it is located beside your program's .exe file. Similarly, on the Release folder you have to copy allegro_monolith-5.1.dll beside that folder's executable. Both of this files should be on the allegro\bin\ directory of the downloaded archive. Keep in mind that you would probably need another dll from the ones I said, but it should also be included on the file you downloaded from Gna!.

Note: The package I linked to only provides the base Allegro 5 library, not its dependencies. Supposedly the release binary has them included but the Debug version may need you to link them manually. They are located here. Select the 1.2.0 package for the newest version of allegro 5.1.12.

这篇关于Allegro 5 Visual Studio 2015吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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