我正在尝试在我的 OSX Sonoma 14.4.1 上使用 ADA(通过 Alire 和 gnat_native 工具链)和 SDL2 编写一个小游戏。
对于 Ada,我正在使用 Alire,从我所看到的来看,我有最新的 gnat 本机版本(根据 https://alire.ada.dev/crates/gnat_native):
> alr --version
alr 2.0.1
> alr toolchain
CRATE VERSION STATUS NOTES
gprbuild 22.0.1 Default
gnat_native 13.2.2 Default
我使用以下命令
alr with sdlada
将 SDL 绑定添加到我的项目中,但是当我尝试在 Mac 上使用 alr build
构建它时,出现以下错误:
> alr build
ⓘ Running pre-build actions for sdlada=2.5.20...
mkdir -p gen/src/
ⓘ Building tictactoe=0.1.0-dev/tictactoe.gpr...
Compile
[C] version_ttf.c
[C] version_images.c
[C] version.c
In file included from /usr/local/include/SDL2/SDL_platform.h:76,
from /usr/local/include/SDL2/SDL_config.h:33,
from /usr/local/include/SDL2/SDL_stdinc.h:31,
from /usr/local/include/SDL2/SDL_main.h:25,
from /usr/local/include/SDL2/SDL.h:32,
from /Users/stefano/.local/share/alire/builds/sdlada_2.5.20_cd53c280/42d3242441b923cdce0d399fdf8d3b6b1a75d0874241c5467499cc92113894c2/src/version.c:4:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/TargetConditionals.h:140:50: error: missing binary operator before token "("
140 | #if !defined(__has_extension) || !__has_extension(define_target_os_macros)
| ^
In file included from /usr/local/include/SDL2/SDL_platform.h:76,
from /usr/local/include/SDL2/SDL_config.h:33,
from /usr/local/include/SDL2/SDL_stdinc.h:31,
from /usr/local/include/SDL2/SDL_main.h:25,
from /usr/local/include/SDL2/SDL.h:32,
from /usr/local/include/SDL2/SDL_image.h:32,
from /Users/stefano/.local/share/alire/builds/sdlada_2.5.20_cd53c280/42d3242441b923cdce0d399fdf8d3b6b1a75d0874241c5467499cc92113894c2/src/image/version_images.c:4:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/TargetConditionals.h:140:50: error: missing binary operator before token "("
140 | #if !defined(__has_extension) || !__has_extension(define_target_os_macros)
| ^
In file included from /usr/local/include/SDL2/SDL_platform.h:76,
from /usr/local/include/SDL2/SDL_config.h:33,
from /usr/local/include/SDL2/SDL_stdinc.h:31,
from /usr/local/include/SDL2/SDL_main.h:25,
from /usr/local/include/SDL2/SDL.h:32,
from /usr/local/include/SDL2/SDL_ttf.h:39,
from /Users/stefano/.local/share/alire/builds/sdlada_2.5.20_cd53c280/42d3242441b923cdce0d399fdf8d3b6b1a75d0874241c5467499cc92113894c2/src/ttf/version_ttf.c:4:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/TargetConditionals.h:140:50: error: missing binary operator before token "("
140 | #if !defined(__has_extension) || !__has_extension(define_target_os_macros)
| ^
compilation of version.c failed
compilation of version_images.c failed
compilation of version_ttf.c failed
gprbuild: *** compilation phase failed
这似乎是 OSX SDK 库本身引发的错误。
我认为这个 SDL 安装是有效的,因为我一直在用 C++ (C++20) 编写并通过 CMake/Clang 编译的不同项目中使用它。
从这篇文章中获得灵感https://github.com/orgs/Homebrew/discussions/5195问题似乎是因为正在使用的预处理器(我不知道如何找出是哪个)是吗)不支持
__has_extension
,这是 C++17 功能。
有什么方法可以指示 Alire/toolchain/gnat_native 使用支持此功能的不同 C++ 编译器吗?或者强制
alr build
使用的编译器使用C++17标准?或者有没有办法使用不同的工具链来支持这一点(可能通过 Alire)?或者有一种方法可以让 SDL ADA 绑定到我已经安装在我的机器上的静态或动态编译(通过 home-brew)?
那是我在 Homebrew 网站上提出的问题!我觉得看起来很熟悉!
以下文件位置特定于 Alire 2.0,早期 Alire 版本的组织方式不同。
在
~.local/share/alire
下,您会发现3个目录:
toolchains
包含..工具链版本。releases
包含下载的板条箱版本。builds
包含使用特定工具缓存的包构建。现在你有一个(不成功的)构建,最后一个将被填充,所以从那里继续,
sdlada
;我有sdlada_2.5.20_cd53c280
。cd
进入其中(如果有多个,我想你可以使用最新的)。build/gnat/sdlada.gpr
:@@ -36,6 +36,7 @@ library project SDLAda is
for Library_Kind use "static";
package Compiler is
+ for Driver ("C") use "clang";
Common_Switches := ("-ffunction-sections", "-fdata-sections");
C_Switches := ();
Ada_Switches := ("-gnat2012", "-gnata", "-gnato", "-gnatwa",
这在很大程度上是一个解决方法!正确的解决方案需要从源头进行。 您想在 sdlada 的 Github 存储库 上发布问题吗?还是由我来发布?