Skip to content

error "linker command failed" when building the application made with go bindings #1899

Closed
@arshamalh

Description

@arshamalh

Scenario:

git clone https://github.com/ggerganov/whisper.cpp
cd whisper.cpp/bindings/go && make whisper
cd ../.. && make base.en

go get github.com/ggerganov/whisper.cpp/bindings/go
# and import and use "github.com/ggerganov/whisper.cpp/bindings/go/pkg/whisper" in my app

Everything is all right till now,
But when I run:

LIBRARY_PATH=${PWD}/whisper.cpp C_INCLUDE_PATH=${PWD}/whisper.cpp go build .

I get this output:

/opt/homebrew/Cellar/go/1.21.0/libexec/pkg/tool/darwin_arm64/link: running cc failed: exit status 1
ld: Undefined symbols:
  _MTLCopyAllDevices, referenced from:
      _ggml_metal_init in libwhisper.a[7](ggml-metal.o)
  _MTLCreateSystemDefaultDevice, referenced from:
      _ggml_backend_metal_buffer_type_alloc_buffer in libwhisper.a[7](ggml-metal.o)
      _ggml_backend_metal_buffer_type_get_max_size in libwhisper.a[7](ggml-metal.o)
      _ggml_backend_metal_buffer_from_ptr in libwhisper.a[7](ggml-metal.o)
      _ggml_metal_init in libwhisper.a[7](ggml-metal.o)
  _OBJC_CLASS_$_MTLCaptureDescriptor, referenced from:
       in libwhisper.a[7](ggml-metal.o)
  _OBJC_CLASS_$_MTLCaptureManager, referenced from:
       in libwhisper.a[7](ggml-metal.o)
  _OBJC_CLASS_$_MTLCompileOptions, referenced from:
       in libwhisper.a[7](ggml-metal.o)
  _OBJC_CLASS_$_MTLComputePassDescriptor, referenced from:
       in libwhisper.a[7](ggml-metal.o)
  _OBJC_CLASS_$_NSBundle, referenced from:
       in libwhisper.a[7](ggml-metal.o)
  _OBJC_CLASS_$_NSProcessInfo, referenced from:
       in libwhisper.a[7](ggml-metal.o)
  _OBJC_CLASS_$_NSString, referenced from:
       in libwhisper.a[7](ggml-metal.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)

make: *** [build] Error 1

I also tried to replace the whisper package in go.mod with the cloned one, but nothing happened.


The weird thing is that my docker image on Github actions pipeline follows the same approach but that is working just fine, here's my dockerfile:

FROM golang:1.20-bullseye as builder
WORKDIR /app
RUN git clone https://github.com/ggerganov/whisper.cpp
RUN cd whisper.cpp/bindings/go && make whisper
RUN cd whisper.cpp && make base.en
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN go mod edit -replace=github.com/ggerganov/whisper.cpp/bindings/go=./whisper.cpp/bindings/go
RUN make build

FROM debian:bookworm-20210816
COPY --from=builder /app/main /bin/main
COPY --from=builder /app/whisper.cpp/models/ggml-base.en.bin aimodels/ggml-base.en.bin
ENTRYPOINT [ "main" ]

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