New Go programmer here -- apologies in advance for any misused terminology or convention breaking -- I'm still getting up to speed on the language. I'm trying to use this sql lite package in my go programs, and sometimes my program will fail with the following error
# command-line-arguments
/usr/local/go/pkg/tool/darwin_amd64/link: cannot open file
/usr/local/go/pkg/darwin_amd64/github.com/mattn/go-sqlite3.a: open
/usr/local/go/pkg/darwin_amd64/github.com/mattn/go-sqlite3.a: no such
file or directory
This happens when I try to run my program with go run main.go
. The go-sqlite3.a
file exists in my workspace package, but go doesn't want to load it for for some reason. This only seems to happen when I try importing the module from a — sub-package (? not sure if this is the right term).
If I do the following in a single main.go
file
package main
import(
"fmt"
_ "github.com/mattn/go-sqlite3"
)
func main(){
fmt.Println("Hello World from main()")
}
everything works fine. However, if I add a package to my program so the file structure is laid out like this
main.go
test/test.go
and I include my package (in main.go
) like this
import(
"fmt"
"./test"
)
func main(){
test.Test()
}
and my package (test/test.go
) looks like this
package test
import(
"fmt"
_ "github.com/mattn/go-sqlite3"
)
func Test(){
fmt.Println("Hello World from Test() in test/test.go")
}
then go run main.go
fails with the above error message.
Does anyone know what's going on here? Is it wrong to use a ./
in my import? I've tried reading up on this online, but I've had trouble finding something that addresses the behavior I'm seeing and the reasons for it.