20

I'm trying to use a cgo library on Windows, namely github.com/mattn/go-sqlite3

I use Cygwin64 and installed with all "Development" packages, so gcc is availabe.

But running go get github.com/mattn/go-sqlite3 results in:

/usr/lib/gcc/x86_64-pc-cygwin/5.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingwex
/usr/lib/gcc/x86_64-pc-cygwin/5.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingw32

If I search for "mingwex" and "mingw32" in the Cygwin installer, I get no results. Am I looking for the wrong names or are they not available on 64 bit systems?

Or is there a better way to use the library on Windows?


Note that the README states that

However, if you install go-sqlite3 with go install github.com/mattn/go-sqlite3, you don't need gcc to build your app anymore

but I get the same error message if I use go install.

$ go version
go version go1.6.2 windows/amd64
Fabian Schmengler
  • 24,155
  • 9
  • 79
  • 111
  • 1
    gcc is for building on Cygwin for Cygwin. mingw32 is for building for Windows. May be you want to use the cross compiler `/usr/bin/x86_64-w64-mingw32-gcc.exe` from Cygwin to Windows ? – matzeri May 28 '16 at 09:47
  • @matzeri thanks for the suggestion, but I can't figure out how to tell go, which `gcc` binary to use. Actually, building for cygwin would be fine for me too, if I can get it to work. Any ideas? – Fabian Schmengler May 28 '16 at 10:02
  • I do not see go as cygwin package, so building for cygwin seems complicated. Look if setting CC or GCC variable is effective – matzeri May 28 '16 at 12:55
  • On mingw64 I needed to install `mingw-w64-x86_64-gcc` – isalgueiro May 23 '17 at 14:36

3 Answers3

14

What finally worked for me (instead of Cygwin) is to download TDM MinGW-w64 from http://tdm-gcc.tdragon.net/download and set the PATH such that gcc from C:\TDM-GCC-64\bin is used.

Fabian Schmengler
  • 24,155
  • 9
  • 79
  • 111
  • For reference, the issue is clarified [here](https://android.googlesource.com/platform/external/cherry/+/master/README) `- MinGW: http://www.mingw.org/ * add "c:\MinGW\bin" to PATH * run "mingw-get install gcc" * required for building sqlite Go package * note: using Cygwin GCC doesn't work` – N0dGrand87 Apr 18 '19 at 00:12
4

You can also install package mingw64-i686-gcc-core from Cygwin.

The binary will be /usr/bin/i686-w64-mingw32-gcc.exe so you probably need to copy it as /usr/bin/gcc.exe.

iqqmuT
  • 653
  • 6
  • 8
  • ```/usr/bin/gcc.exe``` file is already present. Should I replace it with the existing ```gcc.exe``` file? – Mahesh Sep 21 '21 at 07:07
  • This works for me, too. I installed mingw64-x86_64-gcc-core (not i686) via cygwin setup and then: `export CC='D:\cygwin64\bin\x86_64-w64-mingw32-gcc.exe'` – ce72 Feb 24 '23 at 12:36
1

I have encountered the same issue as well. It seems to me that cygwin is not fully compatible with cgo. Instead, I have used https://mingw-w64.org.

From the cgo documentation https://github.com/golang/go/wiki/cgo:

In order to use cgo on Windows, you'll also need to first install a gcc compiler (for instance, mingw-w64) and have gcc.exe (etc.) in your PATH environment variable before compiling with cgo will work.

Tomer
  • 1,594
  • 14
  • 15