如何使CMake识别SFML

huangapple go评论78阅读模式
英文:

How to make CMake recognize SFML

问题

我正在尝试编写一个简单的国际象棋应用程序,稍后将用于制作我的国际象棋引擎。我正在使用C++和SFML库(或者至少我想要使用它)。

我使用Visual Studio Code,我有Mac OS 12.6.6,无法升级到Mac OS 13,因为我的Mac太旧,因此无法下载最新的XCode,也不能下载适用于我的Mac的XCode版本,除非支付苹果开发者计划的费用,而我不会这样做。

我对CMake完全不熟悉,也不知道是否有更好的替代方案(如果有的话),而且(根据我理解的情况)我必须使用类似CMake的工具来使SFML工作。问题是,我不知道如何让它工作。

我尝试过复制我在互联网上找到的各种解决方案,但是没有一个真正针对我的情况,因此没有一个有效。通常,我会收到以下错误:

[cmake] CMake Error at CMakeLists.txt:6 (find_package):
[cmake]   By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
[cmake]   asked CMake to find a package configuration file provided by "SFML", but
[cmake]   CMake did not find one.
[cmake] 
[cmake]   Could not find a package configuration file provided by "SFML" with any of
[cmake]   the following names:
[cmake] 
[cmake]     SFMLConfig.cmake
[cmake]     sfml-config.cmake
[cmake] 
[cmake]   Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
[cmake]   "SFML_DIR" to a directory containing one of the above files.  If "SFML"
[cmake]   provides a separate development package or SDK, be sure it has been
[cmake]   installed.

目前,我的CMakeLists.txt如下所示:

cmake_minimum_required (VERSION 3.26.4)
project (Kenobi-bot-chess-engine
VERSION 0.1
DESCRIPTION "Chess engine in C++")

find_package(SFML REQUIRED)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(Kenobi-bot-chess-engine ${SFML_LIBRARIES})

add_executable(Kenobi-bot-chess-engine main.cpp)

再次强调,我以前从未使用过CMake,目前对我来说有些困惑,因此这个问题可能很愚蠢,问题可能很简单,但我会感激任何帮助。

英文:

I am trying to write a simple chess app that I will later use for making my own chess engine. I am using C++ and SFML library (or at least I want to use it).

I am using Visual Studio Code, I have Mac OS 12.6.6 and I can't upgrade it to Mac OS 13 because my Mac is too old, therefore I cannot download the latest XCode and (from what I understand) I cannot download the version of XCode that would work on my Mac without paying for Apple developer programme, which I won't do.

I'm a complete newbie to CMake and I don't know any better alternatives (if there are), and (again, from what I understand) I have to use something like CMake to make SFML work. The problem is I have no idea how to make it work.

I've tried copying various solutions I've found in the internet, but none of them were really addressing exactly my situation and so none of them worked. Usually, I get an error:

[cmake] CMake Error at CMakeLists.txt:6 (find_package):
[cmake]   By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
[cmake]   asked CMake to find a package configuration file provided by "SFML", but
[cmake]   CMake did not find one.
[cmake] 
[cmake]   Could not find a package configuration file provided by "SFML" with any of
[cmake]   the following names:
[cmake] 
[cmake]     SFMLConfig.cmake
[cmake]     sfml-config.cmake
[cmake] 
[cmake]   Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
[cmake]   "SFML_DIR" to a directory containing one of the above files.  If "SFML"
[cmake]   provides a separate development package or SDK, be sure it has been
[cmake]   installed.

Currently, my CMakeLists.txt looks like this:

cmake_minimum_required (VERSION 3.26.4)
project (Kenobi-bot-chess-engine
VERSION 0.1
DESCRIPTION "Chess engine in C++")

find_package(SFML REQUIRED)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(Kenobi-bot-chess-engine ${SFML_LIBRARIES})

add_executable(Kenobi-bot-chess-engine main.cpp)

Again, I've never used CMake before and, as for now, it is rather confusing for me, so it's quite possible that this question is silly and the problem is easy, but I'd appreciate any help.

答案1

得分: 1

总的来说,cmake、qmake、make等只是将您的代码链接/转换成实际可运行的方式。在使用sfml时,Visual Studio并不是您唯一可以用来制作sfml应用程序的程序。另一个很好的例子是qt creator。我建议您查看官方的逐步指南,了解如何在您的Mac机器上安装和配置sfml。我会发送一个链接到通用安装指南,另一个链接到Xcode指南。也许您正在尝试使用更新的sfml版本,或者在旧的Xcode版本中使用它们。由于您的限制,您将不得不查看哪个版本需要什么依赖项,以及您需要安装它们的版本。

通用安装:
https://www.sfml-dev.org/tutorials/2.6/start-vc.php

Xcode安装:
https://www.sfml-dev.org/tutorials/2.6/start-osx.php

如果您感觉额外有趣,您也可以自行编译它:
https://www.sfml-dev.org/tutorials/2.6/compile-with-cmake.php

希望对您有所帮助,祝您好运!

英文:

So in a nutshell the cmake, qmake, make and others are just a way to link / change ur code into an actual working thing. When it comes to the sfml, visual studio is not the only program that you can use to make sfml applications. Another good example is qt creator. I suggest you look at the official step by step guide to how to install and configure sfml on your mac machine. I'll send one link to the general installation guide and another to the xcode guide. Maybe you're trying to use a newer sfml version or such with an old xcode version. Because of your limitidness you'll have to look into what version needs what dependencies AND at what version of them you need to install.

General installation:
https://www.sfml-dev.org/tutorials/2.6/start-vc.php

Xcode installation:
https://www.sfml-dev.org/tutorials/2.6/start-osx.php

And if you're feeling extra spicy you can also compile it yourself:
https://www.sfml-dev.org/tutorials/2.6/compile-with-cmake.php

Hope this helps and good luck!

huangapple
  • 本文由 发表于 2023年7月3日 18:42:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76603977.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定