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

'libsql.h' file not found #21

Open
risico opened this issue Mar 22, 2024 · 5 comments
Open

'libsql.h' file not found #21

risico opened this issue Mar 22, 2024 · 5 comments

Comments

@risico
Copy link

risico commented Mar 22, 2024

Just signed up to try Turso as a huge fan of SQLite but sadly encountered a weird bug right off the bat.

I say weird because when I try the the sample code as a standalone, in a separate go project it works asp expected, but when I try to integrate it into my bigger project it crashes with the following error:

# github.com/tursodatabase/go-libsql
vendor/github.com/tursodatabase/go-libsql/libsql.go:16:10: fatal error: 'libsql.h' file not found
#include <libsql.h>
         ^~~~~~~~~~
1 error generated.

Sharing the code I used, although nothing fancy, just the example code take off the documentation.

func main() {
    dbName := "local.db"
    primaryUrl := "libsql://url.turso.io"
    authToken := "<token>"

    dir, err := os.MkdirTemp("", "libsql-*")
    if err != nil {
        fmt.Println("Error creating temporary directory:", err)
        os.Exit(1)
    }
    defer os.RemoveAll(dir)

    dbPath := filepath.Join(dir, dbName)
    connector, err := libsql.NewEmbeddedReplicaConnector(dbPath, primaryUrl,
        libsql.WithAuthToken(authToken),
    )
    if err != nil {
        fmt.Println("Error creating connector:", err)
        os.Exit(1)
    }
    defer connector.Close()

    db := sql.OpenDB(connector)
    defer db.Close()
}

It is pretty late around here and I am a bit spent, so there might be a chance I am doing something stupid. Currently my only hunch is that there might be some sort of conflict with the other sqlite packages, although not sure how that'd be possible.

@risico
Copy link
Author

risico commented Mar 22, 2024

OK, I think I found the issue, there is a conflict with antlrv4.

go: github.com/antlr/antlr4/runtime/Go/antlr/[email protected]: parsing go.mod:
        module declares its path as: github.com/antlr4-go/antlr/v4
                but was required as: github.com/antlr/antlr4/runtime/Go/antlr/v4
        restoring github.com/antlr/antlr4/runtime/Go/antlr/[email protected]

Making a PR, gonna check if updating the path fixes my issue.

@risico
Copy link
Author

risico commented Mar 22, 2024

Went even more into the rabbit whole and it seems that Antlr moved their Go runtime into its own dedicated repo as per their documentation:
image

I tried to change the repo and the dependencies inside the go-libsql but it seems it the changes reach up to github.com/libsql/sqlite-antlr4-parser.

I'll try and open up an MR in github.com/libsql/sqlite-antlr4-parser so we can fix that, then once that's merged, pull it in go-libsql and get the fix done here as well.

@risico
Copy link
Author

risico commented Mar 23, 2024

Here is the PR to change the path for libsql/sqlite-antlr4-parser: libsql/sqlite-antlr4-parser#4

Once that gets merged I'll make the PR for this repo.

@ryanskidmore
Copy link

I've just run into this same issue 😞 My project still uses vendoring, and I noticed that the libsql.h file is nowhere to be found within the vendored directory. Could that be caused by this same issue, or is it a different one? The library mentioned seems mostly unrelated to this issue.

@soky314
Copy link

soky314 commented Aug 13, 2024

I've just run into this same issue. Our project is using vendoring. I resolved this issue with manual copy of folder"lib" into vendored folder of go-libsql
The problem is that go mod -vendor pruned the "lib" folder, which contains the C code needed to build this package.
golang/go#26366

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

No branches or pull requests

3 participants