Running gcc failed: exit status 1

go version go1.19.3 windows/amd64

I’m trying to use this package for sqlite with encrypted database.
https://github.com/CovenantSQL/go-sqlite3-encrypt#installation

It states I require “gcc” (no idea what that is).

So I download “GCC 12.2.0” Winx64 version and extract the “mingw64” folder to root of C
https://winlibs.com/#download-release

I then add the bin folder path in there to my system path list.

I did this:
go install github.com/CovenantSQL/go-sqlite3-encrypt

I have this in the “go env” list as instructed:
CGO_ENABLED=1

When i attempt to do: “go run main.go” I now get this and I have no idea what it means. Please assist - thanks.

sqlite3-binding.c: In function 'sqlite3SelectNew':
sqlite3-binding.c:121469:10: warning: function may return address of local variable [-Wreturn-local-addr]
121469 |   return pNew;
       |          ^~~~
sqlite3-binding.c:121431:10: note: declared here
121431 |   Select standin;
       |          ^~~~~~~
# command-line-arguments
S:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[username]\AppData\Local\Temp\go-link-138338206\000015.o: in function `_cgo_preinit_init':
\\_\_\runtime\cgo/gcc_libinit_windows.c:40: undefined reference to `__imp___iob_func'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[username]\AppData\Local\Temp\go-link-138338206\000015.o: in function `x_cgo_notify_runtime_init_done':
\\_\_\runtime\cgo/gcc_libinit_windows.c:105: undefined reference to `__imp___iob_func'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[username]\AppData\Local\Temp\go-link-138338206\000015.o: in function `_cgo_beginthread':
\\_\_\runtime\cgo/gcc_libinit_windows.c:149: undefined reference to `__imp___iob_func'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[username]\AppData\Local\Temp\go-link-138338206\000016.o: in function `x_cgo_thread_start':
\\_\_\runtime\cgo/gcc_util.c:18: undefined reference to `__imp___iob_func'
collect2.exe: error: ld returned 1 exit status
package main

import (
	"database/sql"
	"log"

	_ "github.com/CovenantSQL/go-sqlite3-encrypt"
)

func main() {
	db, err := sql.Open("sqlite3", "file:Directory.db?_crypto_key=blahblah")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

}

Hi @rlilewis ,

What did go install return?
Does it work better if you run go get instead`?

I am asking because Go library packages are usually fetched through go get.

The library you are trying to use requires a working C toolchain as it is using “CGO”. Those are not trivial to set up on windows.

If WSL is not an option you should use a CGO free sqlite driver. The first hit on my prefered findmachine is this:

1 Like

Thanks i’ll have a look at that, however I suspect it lacks the DB encryption functionality I was specifically looking for.

So i’m not sure how best to proceed. I might encounter other packages that I need but requires this cgo thing so it might be best if I learn it now.

Are there any guides to set this up on Windows or is it better to develop the application on a different OS? Ultimately my target platform is Windows so I might still have the same issues.


Found this one:
https://pkg.go.dev/github.com/Daskott/gorm-sqlite-cipher#section-readme

I’ll give that one a try.

For anyone interested. I think (fingers crossed) I got this gcc thing working.

  • download the exe labelled “64+32-bit MinGW-w64 edition”
  • install it with all default options (next, next finish)
  • close/reopen vscode if already open so it can use the new path variable that gets created by the installer

based upon guide found here:

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.