Android ndk-build error: undefined symbol: aligned_alloc

Android ndk-build error: undefined symbol: aligned_alloc

我正在尝试为 ImageMagick 库构建共享对象 (.so) 文件,但是由于创建 .so 文件时出现以下错误而卡住了

[arm64-v8a] Executable     : magick
ld: error: undefined symbol: aligned_alloc
>>> referenced by memory.c:262 (././ImageMagick-7.0.9-17/MagickCore\memory.c:262)
>>>               memory.o:(AcquireAlignedMemory) in archive ./obj/local/arm64-v8a/libmagickcore-7.a
>>> referenced by memory.c:262 (././ImageMagick-7.0.9-17/MagickCore\memory.c:262)
>>>               memory.o:(AcquireVirtualMemory) in archive ./obj/local/arm64-v8a/libmagickcore-7.a
>>> referenced by memory.c:262 (././ImageMagick-7.0.9-17/MagickCore\memory.c:262)
>>>               memory.o:(AcquireVirtualMemory) in archive ./obj/local/arm64-v8a/libmagickcore-7.a
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [C:/hostedtoolcache/windows/ndk/r22b/x64/build//../build/core/build-binary.mk:741: obj/local/arm64-v8a/magick] Error 1
Error: Process completed with exit code 1.

我对 C++ 有非常基本的了解,如果我遗漏了什么,欢迎任何建议。 这是 GitHub 操作 link 我正在生成 .so 文件并面临错误以便于重现问题。

https://github.com/malaythecool/Android-ImageMagick7/runs/2316777388?check_suite_focus=true

从 CI 日志中,它显示

././ImageMagick-7.0.9-17/MagickCore/memory.c:262:10: warning: implicit declaration of function 'aligned_alloc' is invalid in C99 [-Wimplicit-function-declaration]

最终导致链接器抱怨缺少符号

ld: error: undefined symbol: aligned_alloc

尝试将标志 -std=c++1z 添加到您的构建配置中,因为 aligned_alloc() 是在 C++17 中引入的。

编辑:

似乎 Application.mk 已经设置了 -std=c++17 here。您能否也尝试添加以下标志:

APP_CONLYFLAGS += -std=c11

确保 C 标准更新为 C11 其中引入了 alloc_aligned()