Description
When i build with gorm and sqlite, Then start the binary,I got the errors:
[error] failed to initialize database, got error Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub
[LOG-debug] 2023/07/19 20:59:36 Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub
[root@VM-0-13-centos ]# Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stu
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: ckganesan
As of my last knowledge update in September 2021, Go applications that use the go-sqlite3 package and require the cgo tool for building (which is the case for go-sqlite3) may need to set the CGO_ENABLED=1 environment variable during the build process. The cgo tool allows Go code to call C code, and some database drivers like go-sqlite3 utilize it to interface with SQLite, which is written in C.
Additionally, you may need to have a C compiler (like GCC) installed and available in your system's PATH so that cgo can properly compile the C code for SQLite. The C compiler is required to build the C code bindings and create the necessary shared object files.
To summarize, when using go-sqlite3, you might need to follow these steps during the build process:
- Set the CGO_ENABLED=1 environment variable to enable cgo support:
$ export CGO_ENABLED=1 - Ensure you have a C compiler (e.g., GCC) installed and available in your system's PATH.
- Run the Go build command for your application.
Keep in mind that tooling and dependencies might change over time, so it's always a good idea to refer to the official documentation of the go-sqlite3 package or any other relevant resources for the most up-to-date instructions on building and using the package. Also, ensure that you have installed the correct version of go-sqlite3 that supports your Go version.
https://pkg.go.dev/github.com/mattn/go-sqlite3#readme-installation
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: saeidee
As @ckganesan mentioned this is not related to gorm but it is related to go-sqlite3 package.