set(SFML_STATIC_LIBRARIES TRUE) 在 Debian 10 Buster 上使用 SFML 2.5.1 在 cmake 中不起作用

set(SFML_STATIC_LIBRARIES TRUE) doesn't work in cmake with SFML 2.5.1 on Debian 10 Buster

我使用命令 "apt install libsfml-dev" 安装了 SFML。

我可以 link 在 cmake 中描述它 post “https://en.sfml-dev.org/forums/index.php?topic=24070.0” 并且一切正常。

但是如果我将 set(SFML_STATIC_LIBRARIES TRUE) 添加到我的 cmake 文件到 link sfml static 我会收到以下错误:

CMake Error at /usr/lib/x86_64-linux-gnu/cmake/SFML/SFMLConfig.cmake:139 (message):
  Requested SFML configuration (Static) was not found
Call Stack (most recent call first):
  CMakeLists.txt:30 (find_package)


CMake Error at CMakeLists.txt:30 (find_package):
  Found package configuration file:

    /usr/lib/x86_64-linux-gnu/cmake/SFML/SFMLConfig.cmake

  but it set SFML_FOUND to FALSE so package "SFML" is considered to be NOT
  FOUND.

我认识到 SFMLConfig.cmake 文件想要访问第 110 行的 SFMLStaticTargets.cmake 文件,如果我设置 (SFML_STATIC_LIBRARIES TRUE)。

但我的 /usr/lib/x86_64-linux-gnu/cmake/SFML 文件夹仅包含以下共享文件 linking:

在 sfml 版本中,我可以在这里下载“https://www.sfml-dev.org/download/sfml/2.5.1/”我也可以在 lib/cmake/SFML 文件夹中找到这些文件,但是 SFMLSharedTargets-release.cmake 文件而不是 SFMLSharedTargets-none.cmake.

我可以在 cmake 中对静态 link sfml 2.5.1 做些什么?

您遇到的错误来自 SFMLConfigDependencies.cmake,更具体地说是最后几行。 sfml_bind_dependency 宏在您的系统中搜索 libXXX.so,其中 XXXSEARCH_NAMES.

之一

我认为安装缺少依赖项的 -dev 包就足够了:

apt install libjpeg-dev libfreetype6-dev libxcb-image0-dev

我在sfml论坛找到答案了!

You have to recompile SFML, because pre-built packages for Linux don't contain static libraries.

https://en.sfml-dev.org/forums/index.php?topic=26837