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

Can't use gorm because the change of crawshaw.io/sqlite #421

Closed
kylege opened this issue Jul 31, 2020 · 16 comments
Closed

Can't use gorm because the change of crawshaw.io/sqlite #421

kylege opened this issue Jul 31, 2020 · 16 comments
Assignees

Comments

@kylege
Copy link

kylege commented Jul 31, 2020

torrent has changed sqlite library to use crawshaw.io/sqlite in this commit 7455b98

I use gorm to manage database, and gorm needs sql diver github.com/mattn/go-sqlite3, as a result, I can't compile my project now:

duplicate symbol _sqlite3_prepare16_v2 in:
    /var/folders/24/0wn_ks8j15375jy_t4tycjf40000gn/T/go-link-184254381/000029.o
    /var/folders/24/0wn_ks8j15375jy_t4tycjf40000gn/T/go-link-184254381/000059.o
ld: 240 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there a workround that we can choose which sqlite lib to use? Maybe add some build flag?

Thanks advance, nice work anyway.

@anacrolix
Copy link
Owner

@hichenming oh dear, this is tricky. Are you aware of a way to allow both to be linked together? If not, I think a tag is the right way forward, as you suggest.

@Zelak312
Copy link

Zelak312 commented Oct 6, 2020

I had the same issue. After searching for many hours I didn't find a way to link them together or anything but I found a way to make it work by allowing multiple definitions with this flag -ldflags "-extldflags=-Wl,--allow-multiple-definition". I don't think it's the best solution to be honest, it feels more like a workaround.

@anacrolix
Copy link
Owner

@Zelak312 @hichenming do you want to try with running go mod edit -replace crawshaw.io/sqlite=github.com/getlantern/sqlite? There should be a fix in there that solves this issue. Please let me know if it works for you.

@Zelak312
Copy link

I tried running after using the command, it still fails to compile and it did create the replace in the go.mod file

/usr/bin/ld: /tmp/go-link-071491094/000052.o: in function `sqlite3_rtree_query_callback':
/home/zelak/go/pkg/mod/github.com/getlantern/[email protected]/./c/sqlite3.c:193496: multiple definition of `sqlite3_rtree_query_callback'; /tmp/go-link-071491094/000028.o:/home/zelak/go/pkg/mod/github.com/mattn/[email protected]+incompatible/sqlite3-binding.c:192344: first defined here
collect2: error: ld returned 1 exit status

@anacrolix
Copy link
Owner

@Zelak312 thanks

@skinner12
Copy link

skinner12 commented Nov 26, 2020

I have the same error and I can't update from 1.15.2 to 1.18.1.

I've tried go mod edit -replace crawshaw.io/sqlite=github.com/getlantern/[email protected] but still the same error

@anacrolix
Copy link
Owner

anacrolix commented Nov 28, 2020

@skinner12 @Zelak312 @hichenming could you confirm that you're using github.com/mattn/go-sqlite3 elsewhere in your application? It's nothing internal to anacrolix/torrent that is using it?

I thought the fix in github.com/getlantern/sqlite would fix this issue, but then ran into it myself with another application I have that used mattn/go-sqlite3 throughout, and tried to use a recent anacrolix/torrent that was using crawshaw.io/sqlite.

I'm not sure what the best way forward is, I expect a tag and/or something linker related is required. I'm not sure it's reasonable to expect anacrolix/torrent to revert to mattn/go-sqlite3, just because that's the most popular module for sqlite3 in Go. It could be possible to break out some of the sqlite stuff in anacrolix/torrent into modules that aren't always depended on, or provide a tag to exclude that stuff so that another sqlite module can be used elsewhere in an application.

@skinner12
Copy link

Hi @anacrolix, I confirm that I'm using sqlite3 elsewhere: I used it for save some infos from downloading torrents and other data.

Anyway, now that my app gets bigger, I choose to use postgresql so I didn't get sqlite3 dependence, the error disappears and I updated to latest version of anacrolix/torrent seamless.

Thanks for your support

@anacrolix
Copy link
Owner

Thanks for the feedback @skinner12 .

@anacrolix
Copy link
Owner

When crawshaw.io/sqlite and mattn/go-sqlite3 are in the same binary, try passing libsqlite3 in the build -tags option. This will only build sqlite3 once using crawshaw.io/sqlite's implementation. For example, when running tests in my package I'm able to do $ go test -tags libsqlite3 ./.... Thanks to https://github.com/joesis for finding this.

@anacrolix
Copy link
Owner

This should be fixed with #421 (comment).

@racoon-devel
Copy link

racoon-devel commented Mar 31, 2023

I have the same issue. And mentioned solution doesn't work...

go get -u gorm.io/gorm
go get -u gorm.io/driver/sqlite

After it:

$ go build -tags libsqlite3 ./rms-torrent.go                                                                                                               
# github.com/anacrolix/missinggo/v2/conntrack
../../../go/pkg/mod/github.com/anacrolix/missinggo/[email protected]/conntrack/instance.go:24:16: cannot use generic type stm.Var[T any] without instantiation
../../../go/pkg/mod/github.com/anacrolix/missinggo/[email protected]/conntrack/instance.go:25:16: cannot use generic type stm.Var[T any] without instantiation
../../../go/pkg/mod/github.com/anacrolix/missinggo/[email protected]/conntrack/instance.go:29:11: cannot use generic type stm.Var[T any] without instantiation
../../../go/pkg/mod/github.com/anacrolix/missinggo/[email protected]/conntrack/instance.go:32:21: cannot use generic type stm.Var[T any] without instantiation
../../../go/pkg/mod/github.com/anacrolix/missinggo/[email protected]/conntrack/instance.go:33:21: cannot use generic type stm.Var[T any] without instantiation

Without gorm all is OK...

@anacrolix
Copy link
Owner

@racoon-devel I am not able to reproduce this. Could you provide a link to your project so I can try build it?

@racoon-devel
Copy link

@racoon-devel I am not able to reproduce this. Could you provide a link to your project so I can try build it?

Sure, branch feature/advanced-torrent
https://github.com/RacoonMediaServer/rms-torrent/tree/feature/advanced-torrent

anacrolix added a commit to anacrolix/rms-torrent that referenced this issue Apr 5, 2023
@anacrolix
Copy link
Owner

I pushed a fix to https://github.com/anacrolix/rms-torrent/tree/feature/advanced-torrent.

For some reason your anacrolix/torrent is stuck on v1.11.0. This happens frequently, it's a combination of golang/go#55955 and golang/go#56494 making it nontrivial to upgrade.

You should find it's fixed if you incorporate the changes in the branch above, and ensure that anacrolix/torrent does not regress to v1.11.0.

@racoon-devel
Copy link

Oh... @anacrolix Thank you so much!

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

5 participants