-
Notifications
You must be signed in to change notification settings - Fork 13
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
cgocall unavailable without CGO_ENABLED=0 #2
Comments
Ah you managed to hit an untested path. So far I only tested with something that uses network functions which includes cgo if not explicitly asked not to do that... |
Hrmpf I investigated a lot only to discover, that I misread your bugreport. CGO_ENABLED=1 doesn't work here if there is no cgo used in the rest of the program... |
Sorry for being unclear @notti Had a test script for my go-sqlite-dynamic repo, compiled it with just ‘go build’ and at runtime it threw that error, however ‘CGO_ENABLE=0 go build’ resulted on a binary that ran fine. I thought you’d hit the nail on the head by saying you’d only tested in apps where real CGO was used elsewhere (i.e. including real C dependancies), where as my app reported being dynamically linked from ‘ldd’ but included nothing calling CGO. Does it default to using the system linker if it is installed and you don’t specify ‘CGO_ENABLED=0’ maybe? On mobile at the moment so will try to provide more clear details tomorrow. |
Hopefully this will help to clarify, the code: package main
import (
"os"
"fmt"
"database/sql"
"github.com/iamacarpet/go-sqlite3-dynamic"
)
func main() {
path := "test.db"
f, err := os.Create(path)
if err != nil {
panic(err)
}
f.Close()
fmt.Println(sqlite3.Version())
db, err := sql.Open(`sqlite3`, path)
if err != nil {
panic(err)
}
r, err := db.Exec(`CREATE TABLE test (
id integer PRIMARY KEY NOT NULL,
name varchar(30)
)`)
if err != nil {
panic(err)
}
_ = r
r, err = db.Exec(`INSERT INTO test(name) VALUES ('first') `)
if err != nil {
panic(err)
}
_, err = r.LastInsertId()
if err != nil {
panic(err)
}
_, err = r.RowsAffected()
if err != nil {
panic(err)
}
r, err = db.Exec(`INSERT INTO test(name) VALUES ('second') `)
if err != nil {
panic(err)
}
_, err = r.LastInsertId()
if err != nil {
panic(err)
}
_, err = r.RowsAffected()
if err != nil {
panic(err)
}
db.Close()
os.Remove(`./test.db`)
} Any my Go version:
The results:
In comparison to the results on a test binary (for the ldd - I was mistaken about what I expected the results to be, but it may be relevant): package main
import (
"fmt"
)
func main() {
fmt.Println("test")
} And the results:
|
Thanks for this example - with this I could reproduce it.
Looks like the problem is that I need another way to detect if I'll try to come up with something different if possible. |
If cgo is enabled, cgo is now used to import dlopen and related functions. Additionally, stuff got cleaned up a bit. This might be a solution for #2
@iamacarpet can you try with latest master? Should work now. |
Hello @notti
Just finishing up my documentation and I noticed in yours it says:
However, building without
CGO_ENABLED=0
always throws me this error:Is this expected behavior?
Regards,
iamacarpet
The text was updated successfully, but these errors were encountered: