torrent: Can't use gorm because the change of crawshaw.io/sqlite

torrent has changed sqlite library to use crawshaw.io/sqlite in this commit https://github.com/anacrolix/torrent/commit/7455b98a0f597c3b84c7ed60b75b9ddf5fd8d341

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.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (9 by maintainers)

Commits related to this issue

Most upvoted comments

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.

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

@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.

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.