如何在 Visual Studio 中使用 SFML?

问题描述 投票:0回答:2

我想编译一些我在 Linux 上编写的 C++ SFML 游戏,以便我的朋友可以玩它,但我不知道如何在 Visual Studio 中编译我的项目。

sfml2.5.1/include
路径添加到“其他包含目录”,将
SFML_STATIC
添加到“预处理器定义”,将
sfml 2.5.1/lib
目录添加到“其他库目录”,并将
sfml-graphics.lib;sfml-window.lib;sfml-system.lib
添加到“其他依赖项”,然后运行它,它说:

致命错误 LNK1181:无法打开输入文件“sfml-graphics.lib”

我尝试将

sfml*.lib
更改为
libsfml*.a
,这里是前 3 行,共 52 行:

1>Game.obj : error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)
1>Game.obj : error LNK2001: unresolved external symbol "public: static class sf::Color const sf::Color::White" (?White@Color@sf@@2V12@B)
1>Game.obj : error LNK2001: unresolved external symbol "public: virtual class sf::Vector2<float> __cdecl sf::CircleShape::getPoint(unsigned __int64)const " (?getPoint@CircleShape@sf@@UEBA?AV?$Vector2@M@2@_K@Z)

这个该怎么办?

c++ sfml visual-studio-2022
2个回答
1
投票

我最近不得不做类似的事情,我发现

vcpkg
非常简单和方便。 我做到了:

> git clone https://github.com/Microsoft/vcpkg.git
> .\vcpkg\bootstrap-vcpkg.bat -disableMetrics
> .\vcpkg\vcpkg integrate install
> .\vcpkg\vcpkg install sfml:x64-windows

然后,在 Visual Studio 项目中,只需包含库标头即可:

#include <SFML/Graphics.hpp>

然后它应该编译和链接,在构建文件夹中为库创建一个 dll。


0
投票

在当前项目的 Visual Studio 中,转到菜单上的“工具”。将鼠标悬停到“命令行”菜单选项,然后选择“开发人员命令提示符”。如果您使用 VS 安装了 vcpkg,则此 CMD 将包含 vcpkg,而普通 CMD 不会。很奇怪,但却是事实。从那里,您可以运行

vcpkg new --application
来生成清单文件
vcpkg add port SFML
,配置 CMakePresets、CMakeLists,以及构建和运行项目。

这些说明可在 Microsoft 的 VCPKG 在线文档中找到。

搜索一下就会找到。

祝你好运。

© www.soinside.com 2019 - 2024. All rights reserved.