Skip to content
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

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

Closed
arshamalh opened this issue Feb 24, 2024 · 4 comments · Fixed by #1944
Closed

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

arshamalh opened this issue Feb 24, 2024 · 4 comments · Fixed by #1944

Comments

@arshamalh
Copy link

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" ]
@VinzentJenner
Copy link

I'm facing the same issue on Apple M3 Pro

@josharian
Copy link
Contributor

Dunno whether this is the right fix, but in bindings/go/whisper.go, try changing

#cgo darwin LDFLAGS: -framework Accelerate

to

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

If you can confirm that works for you, I can maybe send a PR...

@josharian
Copy link
Contributor

Actually, you also need -framework CoreGraphics. Without it, MTLCreateSystemDefaultDevice doesn't find the GPU, which could also help explain some of the speed discrepancies folks have noted.

@josharian
Copy link
Contributor

(There's the additional complication of getting ahold of ggml-metal.metal. Ideally that'd be embedded into the Go binary and passed along to ggml_metal_init as a byte slice. I can work on that too, I guess...but I'd like to see whether PRs are actually getting merged first. :P )

josharian added a commit to josharian/whisper.cpp that referenced this issue Mar 8, 2024
The first two are required to build.
The last one is to make it actually detect the GPU.

Fixes ggerganov#1899, at least for me
ggerganov pushed a commit that referenced this issue Mar 9, 2024
The first two are required to build.
The last one is to make it actually detect the GPU.

Fixes #1899, at least for me
jiahansu pushed a commit to WiseSync/whisper.cpp that referenced this issue Apr 17, 2024
The first two are required to build.
The last one is to make it actually detect the GPU.

Fixes ggerganov#1899, at least for me
viktor-silakov pushed a commit to viktor-silakov/whisper_node_mic.cpp that referenced this issue May 11, 2024
The first two are required to build.
The last one is to make it actually detect the GPU.

Fixes ggerganov#1899, at least for me
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants