Android ndk-build error: undefined symbol: aligned_alloc

I am trying to build Shared Object (.so) files for the ImageMagick library however stuck due to following error while creating .so file

[arm64-v8a] Executable     : magick
ld: error: undefined symbol: aligned_alloc
>>> referenced by memory.c:262 (././ImageMagick-7.0.9-17/MagickCorememory.c:262)
>>>               memory.o:(AcquireAlignedMemory) in archive ./obj/local/arm64-v8a/libmagickcore-7.a
>>> referenced by memory.c:262 (././ImageMagick-7.0.9-17/MagickCorememory.c:262)
>>>               memory.o:(AcquireVirtualMemory) in archive ./obj/local/arm64-v8a/libmagickcore-7.a
>>> referenced by memory.c:262 (././ImageMagick-7.0.9-17/MagickCorememory.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.

I have very basic knowledge on c++, any suggestions are welcome if I am missing something. Here’s GitHub Actions link where I am generating .so file and facing error for ease of reproducing the issue.

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

Answer

From the CI logs, it shows up

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

which finally ends up in the linker complaining for the missing symbol

ld: error: undefined symbol: aligned_alloc

Try adding the flag -std=c++1z to your build configuration since aligned_alloc() was introduced in C++17.

EDIT:

It seems the Application.mk already sets the -std=c++17 here. Could you try adding the following flag too:

APP_CONLYFLAGS += -std=c11

to ensure that the C standard is updated to C11 wherein alloc_aligned() was introduced?