Skip to content

Undefined symbols for architecture arm64: "_MTLCopyAllDevices" #1344

Closed
@lixianmin

Description

@lixianmin

I am using "Apple M1 Max", to compile the lastest commit 91c0b23, it reports the following error:

---------------command line:
cd bindings/go
make examples

-------------- error message:

Mkdir build
Mkdir models
Build whisper
I whisper.cpp build info: 
I UNAME_S:  Darwin
I UNAME_P:  arm
I UNAME_M:  arm64
I CFLAGS:   -I.              -O3 -DNDEBUG -std=c11   -fPIC -D_XOPEN_SOURCE=600 -D_DARWIN_C_SOURCE -pthread -DGGML_USE_ACCELERATE -DGGML_USE_METAL
I CXXFLAGS: -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC -D_XOPEN_SOURCE=600 -D_DARWIN_C_SOURCE -pthread -DGGML_USE_METAL
I LDFLAGS:   -framework Accelerate -framework Foundation -framework Metal -framework MetalKit
I CC:       Apple clang version 14.0.0 (clang-1400.0.29.202)
I CXX:      Apple clang version 14.0.0 (clang-1400.0.29.202)

cc  -I.              -O3 -DNDEBUG -std=c11   -fPIC -D_XOPEN_SOURCE=600 -D_DARWIN_C_SOURCE -pthread -DGGML_USE_ACCELERATE -DGGML_USE_METAL   -c ggml.c -o ggml.o
cc  -I.              -O3 -DNDEBUG -std=c11   -fPIC -D_XOPEN_SOURCE=600 -D_DARWIN_C_SOURCE -pthread -DGGML_USE_ACCELERATE -DGGML_USE_METAL   -c ggml-alloc.c -o ggml-alloc.o
c++ -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC -D_XOPEN_SOURCE=600 -D_DARWIN_C_SOURCE -pthread -DGGML_USE_METAL -c whisper.cpp -o whisper.o
cc -I.              -O3 -DNDEBUG -std=c11   -fPIC -D_XOPEN_SOURCE=600 -D_DARWIN_C_SOURCE -pthread -DGGML_USE_ACCELERATE -DGGML_USE_METAL -c ggml-metal.m -o ggml-metal.o
ar rcs libwhisper.a ggml.o ggml-alloc.o whisper.o ggml-metal.o
Build example go-model-download
Build example go-whisper
# github.com/ggerganov/whisper.cpp/bindings/go/examples/go-whisper
/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
Undefined symbols for architecture arm64:
  "_MTLCopyAllDevices", referenced from:
      _ggml_metal_init in libwhisper.a(ggml-metal.o)
  "_MTLCreateSystemDefaultDevice", referenced from:
      _ggml_metal_init in libwhisper.a(ggml-metal.o)
  "_OBJC_CLASS_$_MTLComputePassDescriptor", referenced from:
      objc-class-ref in libwhisper.a(ggml-metal.o)
  "_OBJC_CLASS_$_NSBundle", referenced from:
      objc-class-ref in libwhisper.a(ggml-metal.o)
  "_OBJC_CLASS_$_NSString", referenced from:
      objc-class-ref in libwhisper.a(ggml-metal.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

if I modify whisper.go line 13 to the following code, the error message will disappear, and will produce libwhisper.a:

#cgo darwin LDFLAGS: -framework Accelerate -framework Foundation -framework Metal

however, when I compile my golang code with whiper.go, it also complains the following error message:

Undefined symbols for architecture arm64:
  "_MTLCopyAllDevices", referenced from:
      _ggml_metal_init in libwhisper.a(ggml-metal.o)
  "_MTLCreateSystemDefaultDevice", referenced from:
      _ggml_metal_init in libwhisper.a(ggml-metal.o)
  "_OBJC_CLASS_$_MTLComputePassDescriptor", referenced from:
      objc-class-ref in libwhisper.a(ggml-metal.o)
  "_OBJC_CLASS_$_NSBundle", referenced from:
      objc-class-ref in libwhisper.a(ggml-metal.o)
  "_OBJC_CLASS_$_NSString", referenced from:
      objc-class-ref in libwhisper.a(ggml-metal.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


Compilation finished with exit code 1

I do not know how to resolve such an error, can you provide any help tips?

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