Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

setup_env.py on MacBook M2 failed #611

Open

Description

When I run setup_env.py, it failed on compiling with CMake and this is the content in logs/compile.log

[  0%] Linking CXX shared library ../../../../bin/libggml-base.dylib
Undefined symbols for architecture arm64:
  "_dequantize_row_i2_s", referenced from:
      _type_traits in ggml.c.o
  "_quantize_i2_s", referenced from:
      _ggml_quantize_chunk in ggml.c.o
ld: symbol(s) not found for architecture arm64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/libggml-base.0.15.3.dylib] Error 1
make[1]: *** [3rdparty/llama.cpp/ggml/src/CMakeFiles/ggml-base.dir/all] Error 2
make: *** [all] Error 2

my environment:

soc: apple m2
ram: 16gb
cmake --version: 4.4.2
clang -v: 21.0.0 (clang-2100.1.1.101

Activity

  1. claudioaldrighettiatroos commented on Sep 5, 2026

    @claudioaldrighettiatroos

    Same failure here, with the root cause and a workaround.

    Environment: MacBook Pro M2 Pro, macOS 26.5.2, Apple clang 21.0.0 (clang-2100.1.1.101), CMake 4.4.3, main @ 0b341e5, submodule 3rdparty/llama.cpp @ 390c3077. Reproduced with the README command python setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_s on a clean build/; logs/compile.log is identical to yours.

    Root cause: ggml/src/ggml.c references quantize_i2_s (in ggml_quantize_chunk) and dequantize_row_i2_s (in type_traits[GGML_TYPE_I2_S]). Both are declared in ggml/src/ggml-quants.h but defined in ggml/src/ggml-cpu/quants.c, i.e. in the ggml-cpu backend library, so libggml-base depends on symbols that live in a library loaded after it. Linux/ELF tolerates undefined symbols in shared objects and resolves them at load time; macOS ld (two-level namespace) and MSVC/lld-link refuse. It is the same defect as the Windows report #595 (PR #606 only addresses the Windows side).

    Suggested fix: implement the I2_S quantize/dequantize routines inside ggml-base (next to the other quantize_*/dequantize_row_* in ggml-quants.c), or stop referencing CPU-backend symbols from ggml.c.

    Workaround (no source change):

    cmake -B build -DBITNET_ARM_TL1=OFF -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
      -DLLAMA_BUILD_TOOLS=ON -DLLAMA_BUILD_EXAMPLES=ON -DLLAMA_BUILD_COMMON=ON -DLLAMA_BUILD_SERVER=ON \
      "-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-undefined,dynamic_lookup"
    cmake --build build --config Release
    

    (setup_env.py re-uses the cached CMake configuration, so you can run it afterwards.) Building static libraries (-DBUILD_SHARED_LIBS=OFF) should also work.

    Heads-up: on M2 and later (any ARM CPU with i8mm) the build then fails at a second, unrelated spot, ggml-cpu.c:1495: use of undeclared identifier 'src1_cont'. I opened #618 for that one. And once both are fixed, I2_S inference on the arm64 binary still produces garbage with the official GGUF, which is #585 / #600 (fix in PR #586). Until those land, a usable path on Apple Silicon is an x86_64 build run under Rosetta 2 (details in #600).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions