2

I've got the TDM-GCC-64 distribution installed, and set to the PATH variable. I still can't install the cgo distribution github.com/mattn/go-sqlite3. I had CygWin installed before I read the most relevant answer to the question (This). However, installing the tdm distrubution has made no difference.

I get the following error on trying to run the application:

c:\go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingwex
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingw32
collect2: error: ld returned 1 exit status

1 Answers1

2

It seems that your Go installation is still using Cygwin distribution to invoke gcc very likely because of PATH environment variable setting. Try prepending your PATH environment variable with path to Mingw64 distribution bin\ directory (this will not persist so you need to try go run in same Command Line window):

set PATH=C:\Path\To\Mingw64\Installation\bin;%PATH%
go run whatever.go

(NOTE: make sure you have \bin there. If your Mingw64 distro is installed in C:\Mingw64 it will be C:\Mingw64\bin)

If above helped and you want to fix this permanently (and you don't depend on Cygwin tools in Command Line as doing below will replace some commands with Mingw64 ones) make sure that in your PATH environment variable path to Mingw64 is before the Cygwin path. You can do this by doing following:

  1. Press Windows Key + R to bring up Run dialog
  2. Type rundll32.exe sysdm.cpl,EditEnvironmentVariables and press Enter to bring System variables dialog
  3. In the top section called User variables for USERNAME double-click the row where Variable column is Path to bring up Edit Environment Variable dialog
  4. Now check if row where is path to your Mingw64 installation /bin directory is above the row where path to your Cygwin installation /bin directory is. If it is below click on it to select it and click Move Up button as many times as needed to bring it above Cygwin path.
  5. Once done close both dialogs with OK button

While you can install mingw64 packages in Cygwin it is very likely not compatible with Go tooling and official documentation recommends Mingw64/MSYS as a compiler suite to get gcc - I strongly recommend using latest distribution linked in documentation.

blami
  • 6,588
  • 2
  • 23
  • 31
  • Thank you for the detailed answer! I removed Cygwin from my system entirely, since I'd installed it solely for this purpose. Moving the Path to Mingw64 to near the top of the environment variables, and then restarting the console and VSCode (which had its own consoles open) did the trick for me. – Devansh Purohit Jan 22 '21 at 11:29