Go-sqlite3: Install without gcc (not possible)

Created on 17 Jun 2015  路  52Comments  路  Source: mattn/go-sqlite3

Is it possible to use the library in Go without recompiling the binaries?https://github.com/lxc/lxd/issues/762#issuecomment-112463214

I mean is it possible to compile binary pieces of SQLite needed be go-sqlite3 and ship them in separate repository, so that only Go itself can be used to assemble the final product together? Maybe Go already provides some helpers/tools to do that?

Most helpful comment

Here are the step by step instructions.

  1. Download and install "tdm64-gcc-5.1.0-2.exe" from http://tdm-gcc.tdragon.net/download.
  2. Go to Program Files and click on "MinGW Command Prompt". This will start a DOS prompt with the correct environment for using MinGW with GCC.
  3. Within this DOS prompt window, navigate to your GOPATH. For example, I went to C:\go-apps.
  4. Enter the following commands: go get -u github.com/mattn/go-sqlite3. Then enter go install github.com/mattn/go-sqlite3
  5. You are done! go-sqlite3 is now installed and ready for use.

All 52 comments

go-sqlite3 is cgo package. so if you want to build app using go-sqlite3, you need gcc.
But if you install go-sqlite3 with go install github.com/mattn/go-sqlite, you don't need gcc.

@mattn the repository github.com/mattn/go-sqlite doesn't exists, and go install github.com/mattn/go-sqlite3 doesn't work too:

C:\ledis>go install github.com/mattn/go-sqlite3
can't load package: package github.com/mattn/go-sqlite3: cannot find package "github.com/mattn/go-sqlite3" in any of:
        C:\Program Files\Dev\Go\src\github.com\mattn\go-sqlite3 (from $GOROOT)
        C:\ledis\src\github.com\mattn\go-sqlite3 (from $GOPATH)

once go get github.com/mattn/go-sqlite3 and do go install github.com/mattn/go-sqlite3.

C:\ledis\src>go get github.com/mattn/go-sqlite3
# github.com/mattn/go-sqlite3
exec: "gcc": executable file not found in %PATH%

As I said in above:

go-sqlite3 is cgo package. so if you want to build app using go-sqlite3, you need gcc.
But if you install go-sqlite3 with go install github.com/mattn/go-sqlite, you don't need gcc.

And I answered to you in https://github.com/mattn/go-sqlite3/issues/212#issuecomment-112969533 We are going circles.

@techtonik once go-sqlite3 is installed, you no longer need gcc. However, you need the compiled package in your $GOPATH/pkg to do this. To do so, you need gcc to build the C dependencies of this project. ie. $GOPATH/pkg/darwin_amd64/github.com/mattn/go-sqlite3.a.

You could probably compile the archive file elsewhere and put it in the $GOPATH to forego gcc. This isn't guaranteed to work, it's much easier to compile the final program and put the binary on the system with no gcc.

@drewwells: the problem is I am able to go get the package but not able to build/install it. Its complaining about "gcc"

github.com/mattn/go-sqlite3

exec: "gcc": executable file not found in %PATH%

@arulrajalivi what OS are you using?

Windows 64

from cygwin if I try which gcc I get
$ gcc --version
gcc (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

getting this from cygwin, so trying to see what to set in the %PATH%
$which gcc
/usr/bin/gcc

Inside a cygwin window, see what go env says

CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

$ go env
set GOARCH=amd64
set GOBIN=$GOROOT\bin
set GOCHAR=6
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Projects\Cloud Solutions\
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1

after adding C:\MinGW\bin, I am getting # github.com/mattn/go-sqlite3
cc1.exe: sorry, unimplemented: 64-bit mode not compiled in. Trying to install the 64 bit version of MinGW but having trouble with that.

as the message, you need to install 64bit gcc.

Early on mattn suggested that you could just "go install ..." but said "go-sqlite" instead of "go-sqlite3". Was this significant?

Or is mattn's last comment, that you need gcc, the absolute truth? Is there a way to install this API without gcc under windows or not?

Ah, it's my fault. :s/go-sqlite/go-sqlite3/g

I have the exact same the problem in windows and I do not understand how Mattm last command solved the problem? what would be the compele command for go insrall?

go get -u github.com/mattn/go-sqlite3

so in windows I get "exec gcc executable %PATH%", it's the same problme you guys discussed above I just do not understand how you resolved it

I can get the package but i can not create the binary because I do not have GCC.

go-sqlite3 is cgo package, so you need to install gcc.

So in windows, I have to install Cygwin, build the binary and put in "GOROOT/PKG", is that what you mean?

  1. install http://msys2.github.io/
  2. launch mingw64_shell.bat or mingw32_shell.bat
  3. go get -u github.com/mattn/go-sqlite3

I still get the exact same error after following the steps you mentioned
image

pacman -S mingw-w64-x86_64-gcc

If it helps anyone, by default, msys2's Pacman seems to install gcc into C:\msys64\mingw64\bin so you'll need to add that directory to your environment PATH variable and restart your programs before gcc will work.

I can close the issue now as it is not possible to use this extension without gcc.

FYI, This is Not installable not Not using

@mattn the users of this extension are developers, and they need to install it to use it first, and this is impossible without _gcc_. It is my understanding how Go stuff works. What do you mean by _using_ if that's not the case?

If you install go-sqlite3 with go install, you can find $GOPATH/pkg/${GOOS}_${GOARCH}/github.com/mattn/go-sqlite3.a . This mean that you don't need to re-compile it if you don't update go runtime. And you can build another package using go-sqlite3 without recompiling go-sqlite3. Then I mean not installable but can use. For example, you can see debian packages that is built as binary package. But go-sqlite3 still is not published as debian package.

This says that go install compiles code too:
https://stackoverflow.com/questions/24878737/what-is-the-difference-between-go-get-and-go-install

I am not able to validate this claim now, because:

>go get github.com/mattn/go-sqlite
# cd .; git clone https://github.com/mattn/go-sqlite E:\go\src\github.com\mattn\go-sqlite
Cloning into 'E:\go\src\github.com\mattn\go-sqlite'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled
package github.com/mattn/go-sqlite: exit status 128

I guess I had enough of yak shaving for this issue. Feel free to close until better time.

go get is not same as go install

As I said in above, if you compile go-sqlite3.a with go install at once, you can uninstall gcc compiler.

I have the same problem on ubuntu 14.04.4 LTS, I tried this:

$ git clone https://github.com/mattn/go-sqlite3
Cloning into 'go-sqlite3'...
remote: Counting objects: 1112, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 1112 (delta 0), reused 0 (delta 0), pack-reused 1110
Receiving objects: 100% (1112/1112), 8.27 MiB | 4.93 MiB/s, done.
Resolving deltas: 100% (588/588), done.
Checking connectivity... done.

$ go install github.com/mattn/go-sqlite3
# github.com/mattn/go-sqlite3
exec: "gcc": executable file not found in $PATH

Any suggestion?

sudo apt-get install build-essential

having the same problem "exec: "gcc": executable file not found in $PATH" :(

@mitradibakar please read all of comments in above.

Its working fine now windows thanks to @mattn and "tdm64-gcc-5.1.0-2.exe" happy coding :)

"tdm64-gcc-5.1.0-2.exe" is the solution.

apt-cyg install mingw64-x86_64-gcc-g++
env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="x86_64-w64-mingw32-gcc" \
    go get github.com/mattn/go-sqlite3

In Cygwin will be fine.

Here are the step by step instructions.

  1. Download and install "tdm64-gcc-5.1.0-2.exe" from http://tdm-gcc.tdragon.net/download.
  2. Go to Program Files and click on "MinGW Command Prompt". This will start a DOS prompt with the correct environment for using MinGW with GCC.
  3. Within this DOS prompt window, navigate to your GOPATH. For example, I went to C:\go-apps.
  4. Enter the following commands: go get -u github.com/mattn/go-sqlite3. Then enter go install github.com/mattn/go-sqlite3
  5. You are done! go-sqlite3 is now installed and ready for use.

msaron - Thank You!

perfect help! Thanks, everyone.

But if you install go-sqlite3 with go install github.com/mattn/go-sqlite, you don't need gcc.

After installing i still need gcc.

go build
C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exec: "gcc": executable file not found in %PATH%

I would like to mention that this package really only needs a GCC in the PATH. No libraries, no special command prompts, nothing else.

The problem with most CGO packages is that the README says "needs GCC", but actually means something like "needs a certain version of GCC from the 32-bit build of Mingw-w64 and also this library, which you have to compile with make (but not GNU make, the other one) in an upside-down Visual Studio Command Prompt with CYGWIN_PATH_MANGLING set to MORE_MAGIC which is only available on Windows ME".

That is why I usually give up and use a different package when I see import "C", which is exactly what I did with go-sqlite3. I went through a whole zoo of embedded databases before I found out that you really just need _any_ GCC, be it MSYS2 or TDM or Cygwin, and you just have to have it in your PATH.

for linux > sudo apt install gcc
then > go get -u github.com/mattn/go-sqlite3

I had the same problem on ubuntu:
4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
the problem seemed that ubuntu has no gcc-5 installed per default...

go install github.com/mattn/go-sqlite3
exec: "gcc-5": executable file not found in $PATH

go get -v github.com/mattn/go-sqlite3
exec: "gcc-5": executable file not found in $PATH

$sudo apt install gcc-5

then it worked

I am using windows machine and I am getting error like

github.com/mattn/go-sqlite3

exec: "gcc": executable file not found in %PATH%

Which GCC have you installed and where?

Which GCC have you installed and where?

https://jmeubank.github.io/tdm-gcc/

Is working fine on windows 10 64

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SaekiRaku picture SaekiRaku  路  3Comments

tiaguinho picture tiaguinho  路  3Comments

jeffreyantony picture jeffreyantony  路  7Comments

anacrolix picture anacrolix  路  6Comments

dylanlyu picture dylanlyu  路  6Comments