本文介绍了在Visual Studio上手动配置SFML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问答集来自很多很多(问题人们尝试手动配置其VS项目时会使用'sfml'"rel =" tag> sfml 库.有时答案不完整或过于具体.

This Q&A post comes from lots and lots of questions related to sfml library when people try to configure manually their VS projects. Sometimes answers aren't complete or they're too specific.

我想在一篇文章中介绍如何配置VS,使其能够静态和动态地使用SFML库.

I would like to compile in a single post how to configure VS to be able to use the SFML library both statically and dynamically.

所以:

1.如何使用sfml 库<动态?

1. How can I configure my VS project with sfml libraries dynamically, in a general way?

2.如何使用sfml 库<以静态方式?

2. How can I configure my VS project with sfml libraries statically, in a general way?

推荐答案

首先,我建议您仔细遵循 SFML教程有关在Visual Studio中配置库的信息,如果出现问题,请检查此答案.


我将这个答案分为两组,如何配置 sfml 作为动态库,以及如何作为静态库.

First, I recommend carefully follow the SFML tutorial about configuring the library in Visual Studio, if something goes wrong, then check this answer.


I will divide this answer in two groups, how to configure sfml as a dynamic library and how to do it as a static library.

  1. 让我们创建一个VS项目(我将使用VS2013和SFML 2.5.1,但与其他版本几乎相同).将其创建为 ConsoleApplication 并选中 Empty Project .

下载sfml ,最好是最新的稳定版本,选择相应的系统(在我的情况下为 Visual C ++ 12 (2013)-64位).将此文件解压缩到您的.vcxproj文件所在的位置.根据您的版本,这将创建一个名为 SFML-X.X.X 的文件夹.

Download sfml libraries, latest stable version preferably, selecting your corresponding system (in my case Visual C++ 12 (2013) - 64-bit). Extract this file where your .vcxproj file is. This will create a folder named SFML-X.X.X depending on your version.

下载外部库,对于我来说 64位版本.在库文件夹中创建一个名为 extlib 的文件夹,并将此外部库放置在此处.

Download the external libraries, in my case 64 bits version. Create a folder called extlib inside the library folder and place this external libraries there.

创建一个main.cpp文件,然后从 SFML教程.

Create a main.cpp file, and paste the example code from SFML tutorials.

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

SFML作为动态库

  1. 转到 Build-> Configuration Manager .如果使用的是64位库,则首先应创建一个新的解决方案平台.单击 Active Solutions Platform->新建,然后从 Win32 配置中选择 x64 复制.我宁愿取消选中 创建新的项目平台.

  1. Go to Build->Configuration Manager. If you are using a 64 bits library, first you should create a new Solution Platform. Click on Active Solutions Platform->New, select x64 copying from Win32 configuration. I prefer to uncheck Create new project platforms.

创建 Debug-Dynamic Release-Dynamic 编译配置文件.选择活动的解决方案平台后,单击(项目的)配置,然后单击新建.您可以将其称为 Debug-Dynamic ,并从Debug配置中复制它(也请取消选中 Create new ... ).重复创建动态发布配置.

Create Debug-Dynamic and Release-Dynamic compilation profiles. With your active solution platform selected, click on Configuration (of the project) and New. You can call it Debug-Dynamic and copy it from Debug configuration (also, uncheck Create new...). Repeat creating a Release-Dynamic configuration.

打开项目属性->调试.选择 Debug-Dynamic (调试动态)配置,并使用此值PATH=$(ProjectDir)\SFML-2.5.1\bin;%PATH%修改字段 Environment .这将指示VS在哪里可以找到.dll库.

Open Project Properties->Debugging. Select Debug-Dynamic configuration and modify field Environment with this value PATH=$(ProjectDir)\SFML-2.5.1\bin;%PATH%. This will indicate VS where .dll libraries can be found.

C/C ++ 部分中,通过添加此路径$(ProjectDir)\SFML-2.5.1\include来修改其他包含目录字段.这将指示VS .hpp文件的位置.

Over C/C++ section, modify Additional include directories field by adding this path $(ProjectDir)\SFML-2.5.1\include. This will indicate VS where .hpp files are located.

Linker 部分中,通过添加此路径$(ProjectDir)\SFML-2.5.1\lib来修改其他库目录字段.这将指示VS在哪里可以找到.lib文件.

On Linker section, modify Additional library directories field by adding this path $(ProjectDir)\SFML-2.5.1\lib. This will indicate VS where .lib files can be found.

最后,在 Linker-> Input 上,通过添加所需的所有.lib文件来修改其他依赖项字段:

Finally, on Linker->Input, modify Additional dependencies field by adding all .lib files needed:

    sfml-audio-d.lib
    sfml-graphics-d.lib
    sfml-network-d.lib
    sfml-system-d.lib
    sfml-window-d.lib

  1. 使用动态发布配置重复步骤3到6. 注意,在第6步中,库文件没有后缀-d,因为它们是发布库
  1. Repeat steps 3 to 6 with Release-Dynamic configuration. Note, on step 6, library files doesn't have -d suffix, because they're release libraries

SFML作为静态库

  1. 转到 Build-> Configuration Manager .创建 Debug-Static Release-Static 编译配置文件.选择活动的解决方案平台后,单击(项目的)配置,然后单击新建.您可以将其称为 Debug-Static 并从Debug配置中复制它(也请取消选中 Create new ... ).重复创建发布静态配置.

  1. Go to Build->Configuration Manager. Create Debug-Static and Release-Static compilation profiles. With your active solution platform selected, click on Configuration (of the project) and New. You can call it Debug-Static and copy it from Debug configuration (also, uncheck Create new...). Repeat creating a Release-Static configuration.

打开项目属性并选择 Debug-Static 配置.在 C/C ++ 部分中,通过添加此路径$(ProjectDir)\SFML-2.5.1\include来修改其他包含目录字段.这将指示VS .hpp文件的位置.

Open Project Properties and select Debug-Static configuration. Over C/C++ section, modify Additional include directories field by adding this path $(ProjectDir)\SFML-2.5.1\include. This will indicate VS where .hpp files are located.

C/C ++ 部分-> Preprocessor *上,通过添加SFML_STATIC定义来修改 Preprocessor定义字段.这将指示预处理器SFML将被静态编译.

On C/C++ section->Preprocessor*, modify Preprocessor definitions field by adding SFML_STATIC definition. This will indicate preprocessor that SFML will be statically compiled.

Linker 部分中,通过添加此路径$(ProjectDir)\SFML-2.5.1\extlib;$(ProjectDir)\SFML-2.5.1\lib;来修改其他库目录字段.这将指示VS,可以在其中找到外部来源和SFML的.lib文件.

Over Linker section, modify Additional library directories field by adding this paths $(ProjectDir)\SFML-2.5.1\extlib;$(ProjectDir)\SFML-2.5.1\lib;. This will indicate VS where .lib files from external sources and from SFML can be found.

最后,在 Linker-> Input 部分中,使用所有需要的.lib文件修改其他依赖项字段:

Finally, on Linker->Input section, modify Additional dependencies field with all .lib files needed:

    sfml-audio-s-d.lib
    sfml-graphics-s-d.lib
    sfml-network-s-d.lib
    sfml-system-s-d.lib
    sfml-window-s-d.lib
    flac.lib
    freetype.lib
    ogg.lib
    openal32.lib
    opengl32.lib
    vorbis.lib
    vorbisenc.lib
    vorbisfile.lib
    winmm.lib
    gdi32.lib
    ws2_32.lib

  1. 使用发布静态配置重复步骤2到5. 注意,在第5步中,库文件没有后缀-d,因为它们是发行库,但它们将保留后缀-s.
  1. Repeat steps 2 to 5 with Release-Static configuration. Note, on step 5, library files doesn't have -d suffix, because they're release libraries, but they'll keep -s suffix.

这篇关于在Visual Studio上手动配置SFML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 05:48