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

CGO: undefined reference to `ggml_type_name' #70346

Closed
ItzCrazyKns opened this issue Nov 14, 2024 · 5 comments
Closed

CGO: undefined reference to `ggml_type_name' #70346

ItzCrazyKns opened this issue Nov 14, 2024 · 5 comments
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@ItzCrazyKns
Copy link

Go version

go version go1.23.2 windows/amd64

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Kusha\AppData\Local\go-build
set GOENV=C:\Users\Kusha\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Kusha\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Kusha\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.23.2
set GODEBUG=
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\Kusha\AppData\Roaming\go\telemetry
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\Kusha\OneDrive\Desktop\Odiff test\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\Kusha\AppData\Local\Temp\go-build1774415570=/tmp/go-build -gno-record-gcc-switches

What did you do?

I am trying to use the stable diffusion CPP in Golang using CGO. Here is my implementation:

package main

// #cgo CFLAGS: -I./ggml/include -I./thirdparty -I./ggml -I./ggml/src -I./
// #cgo CXXFLAGS: -I./ggml/include -I./thirdparty -I./ggml -I./ggml/src -I./
// #cgo LDFLAGS: -lstdc++
// #include <stdio.h>
// #include <string.h>
// #include <sys/types.h>
// #include <stable-diffusion.h>
import "C"
import "fmt"

func main() {
	ctx := C.new_sd_ctx(
		C.CString("C:/Users/Kusha/Downloads/sd-v1-4.ckpt"),
		C.CString(""),
		C.CString(""),
		C.CString(""),
		C.CString(""),
		C.CString(""),
		C.CString(""),
		C.CString(""),
		C.CString(""),
		C.CString(""),
		C.CString(""),
		C.bool(false),
		C.bool(false),
		C.bool(true),
		C.int(4),
		uint32(34), // use C.uint32_t(34) instead of C.uint(34)
		uint32(1),  // same here
		uint32(0),  // and here
		C.bool(false),
		C.bool(false),
		C.bool(false),
	)

	image := C.txt2img(ctx, C.CString("A car"), C.CString(""), C.int(-1), C.float(7.0), C.float(3.5), C.int(512), C.int(512), uint32(0), C.int(20), C.longlong(0), C.int(1), C.float(0.9), C.float(20.), C.bool(false), C.CString(""))

	fmt.Println(image)
}

Here's how my file structure is like:
image.

What did you see happen?

It for some reason says that:

:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o:C:/Users/Kusha/OneDrive/Desktop/Odiff test/ggml_extend.hpp:79: more undefined references to `ggml_backend_tensor_get' follow
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `ggml_tensor_set_f32':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/ggml_extend.hpp:72:(.text+0x6f3c): undefined reference to `ggml_abort'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `ggml_tensor_get_f32':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/ggml_extend.hpp:82:(.text+0x6f5b): undefined reference to `ggml_abort'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `preprocess_canny':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:170:(.text+0x8e1f): undefined reference to `ggml_init'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:189:(.text+0x8eb2): undefined reference to `ggml_new_tensor_4d'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:190:(.text+0x8ee2): undefined reference to `ggml_new_tensor_4d'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:191:(.text+0x8ef2): undefined reference to `ggml_nbytes'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:192:(.text+0x8f31): undefined reference to `ggml_new_tensor_4d'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:193:(.text+0x8f41): undefined reference to `ggml_nbytes'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:195:(.text+0x8f92): undefined reference to `ggml_new_tensor_4d'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:196:(.text+0x8fb7): undefined reference to `ggml_new_tensor_4d'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:197:(.text+0x8fc5): undefined reference to `ggml_dup_tensor'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:198:(.text+0x8fd5): undefined reference to `ggml_dup_tensor'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:199:(.text+0x8fe5): undefined reference to `ggml_dup_tensor'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:200:(.text+0x8ff8): undefined reference to `ggml_dup_tensor'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `ggml_tensor_get_f32':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/ggml_extend.hpp:79:(.text+0x92ad): undefined reference to `ggml_backend_tensor_get'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `preprocess_canny':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:223:(.text+0x9407): undefined reference to `ggml_free'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `ggml_tensor_get_f32':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/ggml_extend.hpp:79:(.text+0x9460): undefined reference to `ggml_backend_tensor_get'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `ggml_tensor_set_f32':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/ggml_extend.hpp:72:(.text+0x94f5): undefined reference to `ggml_abort'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `ggml_tensor_get_f32':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/ggml_extend.hpp:82:(.text+0x9514): undefined reference to `ggml_abort'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `sd_image_to_tensor':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/ggml_extend.hpp:282:(.text+0x9533): undefined reference to `ggml_abort'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `sd_tensor_to_image':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/ggml_extend.hpp:246:(.text+0x9552): undefined reference to `ggml_abort'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `sd_get_system_info':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:396:(.text+0xa235): undefined reference to `ggml_cpu_has_blas'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:397:(.text+0xa294): undefined reference to `ggml_cpu_has_sse3'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:398:(.text+0xa2f3): undefined reference to `ggml_cpu_has_avx'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:399:(.text+0xa352): undefined reference to `ggml_cpu_has_avx2'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:400:(.text+0xa3b1): undefined reference to `ggml_cpu_has_avx512'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:401:(.text+0xa410): undefined reference to `ggml_cpu_has_avx512_vbmi'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:402:(.text+0xa46f): undefined reference to `ggml_cpu_has_avx512_vnni'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:403:(.text+0xa4ce): undefined reference to `ggml_cpu_has_fma'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:404:(.text+0xa52d): undefined reference to `ggml_cpu_has_neon'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:405:(.text+0xa58c): undefined reference to `ggml_cpu_has_arm_fma'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:406:(.text+0xa5eb): undefined reference to `ggml_cpu_has_f16c'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:407:(.text+0xa64a): undefined reference to `ggml_cpu_has_fp16_va'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:408:(.text+0xa6a9): undefined reference to `ggml_cpu_has_wasm_simd'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:409:(.text+0xa708): undefined reference to `ggml_cpu_has_vsx'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `convolve(ggml_tensor*, ggml_tensor*, ggml_tensor*, int)':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/preprocessing.hpp:19:(.text+0x60a1): undefined reference to `ggml_free'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Kusha\AppData\Local\Temp\go-link-3530238099\000005.o: in function `sd_type_name':
C:/Users/Kusha/OneDrive/Desktop/Odiff test/util.cpp:415:(.text+0x9581): undefined reference to `ggml_type_name'
collect2.exe: error: ld returned 1 exit status

What did you expect to see?

For CGO to run the image generation from Stable diffusion CPP

@ianlancetaylor
Copy link
Member

I would expect to see something on your LDFLAGS line like -lggml. Where are those definitions supposed to come from?

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 14, 2024
@ianlancetaylor
Copy link
Member

Note that we don't use the issue tracker for questions about using Go. You will get better and faster answers using a forum. See https://go.dev/wiki/Questions. Thanks.

@ItzCrazyKns
Copy link
Author

I would expect to see something on your LDFLAGS line like -lggml. Where are those definitions supposed to come from?

Hi, I managed to fix that issue by building the libraries for GGML but now I have another issue. How do I convert an int in Golang to C.uint32 while sending it to a C function. I cannot see it anywhere in the docs.

@seankhliao
Copy link
Member

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants