I have 2 project, the first, name as A
, there is a submodule a
imported sqlite3(github.com/mattn/go-sqlite3
). Another B
project import A
's submodule a
, and in another submodule b
, it also import the same sqlite3.
Both A
and B
put there imports under vendor
dir(managed by govendor
). My Golang version is go version go1.12 linux/amd64
.
While build B
(go build main.go
), throwing following errors(too many, part of them):
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/tmp/go-link-281256755/000029.o: In function `callbackTrampoline':
/tmp/go-build/_cgo_export.c:25: multiple definition of `callbackTrampoline'
/tmp/go-link-281256755/000005.o:/tmp/go-build/_cgo_export.c:25: first defined here
/tmp/go-link-281256755/000029.o: In function `stepTrampoline':
...
/home/xxx/go/src/gitlab.xxxxxxxxx.com/xxxxxxxxx-tools/A/vendor/github.com/mattn/go-sqlite3/sqlite3.go:129: multiple definition of `_sqlite3_result_text'
/tmp/go-link-281256755/000009.o:/home/xxx/go/src/gitlab.xxxxxxxxx.com/xxxxxxxxx-tools/A/vendor/github.com/mattn/go-sqlite3/sqlite3.go:129: first defined here
/tmp/go-link-281256755/000033.o: In function `_sqlite3_result_blob':
...
But building A
works well. To testing the error, I started following demo, also with vendor
inited by govendor
, and build ok.
package main
import (
"database/sql"
"fmt"
"gitlab.xxxxxxxxx.com/xxxxxxxxxxxxxxx/A/a"
_ "github.com/mattn/go-sqlite3"
)
func main() {
fmt.Println(a.ModuleVariable) // use submodule `a` just like B is doing
_, _ = sql.Open(`sqlite3`, `test.db`) // use sqlite too
}
I think the compiler first compile A
's sqlite3
, objects are created under /tmp/go-link-281256755/000005.o
(but no this dir after building), then compile B
's importing of sqlite3
and also create a object contains the same-name function, then the compiler find 2 same-name symbols, the linking failed.
How to fix these situation? Is there any golang env settings to avoid these?
After I remove the sqlite3 package under vendor
both of A
and B
, they both use the sqlite3 under ~/go/src/github.com/mattn/go-sqlite3/
, they all build ok. But I can't do these, due to project A
's deploy platform, I must put all dependencies under vendor, is there any another option to use multiple import with the same package?