Skip to content

undefined reference to `sqrt'  #84

Closed

Description

@fayfive

I compile examples/simple-go-cgo/demo.go with command go build
Here is go env

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/alfred/.cache/go-build'
GOENV='/home/alfred/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/alfred/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/alfred/go'
GOPRIVATE=''
GOPROXY='https://goproxy.io,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.6'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/alfred/working/go/clip_go/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build532488598=/tmp/go-build -gno-record-gcc-switches'

My system is ubuntu 22.04 go version is 1.22.6
I find the include file /usr/include/math.h
the lib /usr/lib/x86_64-linux-gnu/libm.so
Thanks!

Activity

  1. BeeBreeze commented on Aug 14, 2024

    @BeeBreeze

    In makefile:143, move -lm to the end of the command

  2. fayfive commented on Aug 14, 2024

    @fayfive
    Author

    Hello,I don't want to compile the lib, I just want test, I enter the directory example/simple-go-cgo and 'make' and show that

    go build -o demo
    # github.com/asg017/sqlite-vec/examples/go
    /usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
    /usr/bin/ld: /tmp/go-link-3424282799/000002.o: in function `distance_cosine_float':
    /home/alfred/go/pkg/mod/github.com/asg017/sqlite-vec-go-bindings@v0.1.1/cgo/sqlite-vec.c:464: undefined reference to `sqrt'
    /usr/bin/ld: /home/alfred/go/pkg/mod/github.com/asg017/sqlite-vec-go-bindings@v0.1.1/cgo/sqlite-vec.c:464: undefined reference to `sqrt'
    /usr/bin/ld: /tmp/go-link-3424282799/000002.o: in function `distance_cosine_int8':
    /home/alfred/go/pkg/mod/github.com/asg017/sqlite-vec-go-bindings@v0.1.1/cgo/sqlite-vec.c:482: undefined reference to `sqrt'
    /usr/bin/ld: /home/alfred/go/pkg/mod/github.com/asg017/sqlite-vec-go-bindings@v0.1.1/cgo/sqlite-vec.c:482: undefined reference to `sqrt'
    /usr/bin/ld: /tmp/go-link-3424282799/000002.o: in function `vec_normalize':
    /home/alfred/go/pkg/mod/github.com/asg017/sqlite-vec-go-bindings@v0.1.1/cgo/sqlite-vec.c:1747: undefined reference to `sqrtf'
    /usr/bin/ld: /tmp/go-link-3424282799/000002.o: in function `l2_sqr_int8':
    /home/alfred/go/pkg/mod/github.com/asg017/sqlite-vec-go-bindings@v0.1.1/cgo/sqlite-vec.c:374: undefined reference to `sqrtf'
    /usr/bin/ld: /tmp/go-link-3424282799/000002.o: in function `l2_sqr_float':
    /home/alfred/go/pkg/mod/github.com/asg017/sqlite-vec-go-bindings@v0.1.1/cgo/sqlite-vec.c:359: undefined reference to `sqrtf'
    /usr/bin/ld: /tmp/go-link-3424282799/000002.o: in function `l2_sqr_int8':
    /home/alfred/go/pkg/mod/github.com/asg017/sqlite-vec-go-bindings@v0.1.1/cgo/sqlite-vec.c:374: undefined reference to `sqrtf'
    

    I upgrade the example/simple-go-cgo/go.mod

    module github.com/asg017/sqlite-vec/examples/go
    
    go 1.22.5
    
    require github.com/mattn/go-sqlite3 v1.14.22
    
    require github.com/asg017/sqlite-vec-go-bindings v0.1.1
    

    And I found that go/pkg/mod/github.com/asg017/sqlite-vec-go-bindings@v0.1.1/cgo/lib.go

    // #cgo CFLAGS: -DSQLITE_CORE
    // #include "sqlite-vec.h"

    It seems that there is no lib and the directory similarly like this

     // #cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu
    // #cgo LDFLAGS: -ldl -lm

    Can you show me how to compile the sample?
    My system is ubuntu 22.04 go version is 1.22.6
    I find the include file /usr/include/math.h
    the lib /usr/lib/x86_64-linux-gnu/libm.so
    Thanks!

  3. asg017 commented on Aug 15, 2024

    @asg017
    Owner

    @fayfive can you try again with the latest v0.1.2-alpha.7 verision? I added -lm to cgo LDFLAGS for linux environments, hopefully that fixes it

  4. fayfive commented on Aug 15, 2024

    @fayfive
    Author

    Yes, it works well.

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