Skip to content

Error "implicit declaration of function ‘_aligned_malloc’" - swap header order due to MinGW bug? #4707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
svilupp opened this issue Dec 30, 2023 · 2 comments · Fixed by #4736

Comments

@svilupp
Copy link

svilupp commented Dec 30, 2023

First of all, thank you for llama.cpp!

I wanted to build binaries for Windows and I'm getting an error

/workspace/srcdir/llama.cpp/ggml.c:193:35: error: implicit declaration of function ‘_aligned_malloc’; did you mean

It seems to be linked to an old MinGW bug.
The workaround seems to be just moving inclusion of stdlib.h to the top, so it's called before intrin.h in the file ggml.c.
In practice, it would have to be before "ggml-impl.h", because that calls intrih.h.

This workaround seems to be covered in many places, eg, https://stackoverflow.com/a/10862288.

Steps to reproduce:

cmake .. \
    -DCMAKE_INSTALL_PREFIX=$prefix \
    -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
    -DCMAKE_BUILD_TYPE=RELEASE \
    -DBUILD_SHARED_LIBS=ON \
    -DLLAMA_BUILD_TESTS=OFF \
    -DLLAMA_BUILD_EXAMPLES=ON \
    -DLLAMA_NATIVE=OFF \
    -DLLAMA_ACCELERATE=ON \
    -DLLAMA_AVX=ON \
    -DLLAMA_AVX2=ON \
    -DLLAMA_F16C=ON \
    -DLLAMA_FMA=ON \
    -DLLAMA_BLAS=OFF \
    -DLLAMA_CUBLAS=OFF \
    -DLLAMA_CLBLAST=OFF \

Error:

  | [12:08:21] /workspace/srcdir/llama.cpp/ggml.c: In function ‘ggml_init’:
  | [12:08:21] /workspace/srcdir/llama.cpp/ggml.c:193:35: error: implicit declaration of function ‘_aligned_malloc’; did you mean ‘_aligned_realloc’? [-Werror=implicit-function-declaration]

Version: Latest master (b1730)
System: build system for x86_64 (x86_64-w64-mingw32-gcc (GCC) 10.2.0, clang version 16.0.6)
Build log: https://buildkite.com/julialang/yggdrasil/builds/7432#018cba9c-3aff-49f1-a5e3-71ae130b1364

EDIT: The linked build log is for version 1703, but the error persists even for the latest 1730 (tested locally).

@ggerganov
Copy link
Member

Check if #4736 fixes the issue

@svilupp
Copy link
Author

svilupp commented Jan 3, 2024

That was quick! Thank you -- it does indeed fix the error!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants