tursodatabase / libsql

libSQL is a fork of SQLite that is both Open Source, and Open Contributions.
https://turso.tech/libsql
MIT License
11.25k stars 286 forks source link

Go API: Compile/Link error on Linux with Embedded Replication library #1639

Open tmalaher opened 3 months ago

tmalaher commented 3 months ago

Using the quickstart code example at https://docs.turso.tech/sdk/go/quickstart#local-embedded-replicas

Environment:

Compiling the code with go build results in:

go: downloading github.com/tursodatabase/go-libsql v0.0.0-20240725130945-f44f2b84c8c8
go: downloading github.com/tursodatabase/libsql-client-go v0.0.0-20240723183952-b944339d7e70
go: downloading nhooyr.io/websocket v1.8.10
go: downloading github.com/antlr4-go/antlr/v4 v4.13.0
go: downloading golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
go: downloading github.com/libsql/sqlite-antlr4-parser v0.0.0-20240327125255-dbf53b6cbf06
# turso
/emit/lang/go1.22.2/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/home/t823517/go/pkg/mod/github.com/tursodatabase/go-libsql@v0.0.0-20240725130945-f44f2b84c8c8/lib/linux_amd64/libsql_experimental.a(sqlite3mc.c.o): In function `unixDlError':
sqlite3mc.c:(.text+0x3d2a8): undefined reference to `dlerror'
/home/t823517/go/pkg/mod/github.com/tursodatabase/go-libsql@v0.0.0-20240725130945-f44f2b84c8c8/lib/linux_amd64/libsql_experimental.a(sqlite3mc.c.o): In function `unixDlClose':
sqlite3mc.c:(.text+0xef94): undefined reference to `dlclose'
/home/t823517/go/pkg/mod/github.com/tursodatabase/go-libsql@v0.0.0-20240725130945-f44f2b84c8c8/lib/linux_amd64/libsql_experimental.a(sqlite3mc.c.o): In function `unixDlSym':
sqlite3mc.c:(.text+0xefa7): undefined reference to `dlsym'
/home/t823517/go/pkg/mod/github.com/tursodatabase/go-libsql@v0.0.0-20240725130945-f44f2b84c8c8/lib/linux_amd64/libsql_experimental.a(sqlite3mc.c.o): In function `unixDlOpen':
sqlite3mc.c:(.text+0xefb9): undefined reference to `dlopen'
/home/t823517/go/pkg/mod/github.com/tursodatabase/go-libsql@v0.0.0-20240725130945-f44f2b84c8c8/lib/linux_amd64/libsql_experimental.a(sqlite3mc.c.o):(.data.rel+0xb0): undefined reference to `fcntl64'
/home/t823517/go/pkg/mod/github.com/tursodatabase/go-libsql@v0.0.0-20240725130945-f44f2b84c8c8/lib/linux_amd64/libsql_experimental.a(std-90f6ddbf82de36ec.std.409886f6357001f0-cgu.0.rcgu.o): In function `std::sys::unix::weak::fetch::hd6aa2385a244f117':
/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys/unix/weak.rs:138: undefined reference to `dlsym'
collect2: error: ld returned 1 exit status

Using github.com/tursodatabase/libsql-client-go/libsql with "Remote Only" works fine.

MaxTheTurtle0 commented 1 month ago

Did you enable CGO? I also ran into an issue when switching to embedded replicas with Go. I don't have the errors anymore, but for me, the issue was that I wasn't using CGO, which the go-libsql requires.