Go-sqlite3: stdlib.h compile error

Created on 7 Nov 2017  ·  13Comments  ·  Source: mattn/go-sqlite3

Hi,

I'm on linuxmint 18.

I've cloned the repository, installed golang with linuxbrew, go-sqlite3 with go getand launched make binary-linux-x64

I get the following output

# github.com/mattn/go-sqlite3
../../../.go/src/github.com/mattn/go-sqlite3/backup.go:14:20: fatal error: stdlib.h: No such file or directory
compilation terminated.

Any help would be appreciated

Most helpful comment

Never mind !! For me this problem was fixed with sudo apt-get install g++

All 13 comments

please show me your go env

Hi !

Sorry for the delay:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/leonard/.go"
GORACE=""
GOROOT="/home/linuxbrew/.linuxbrew/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/home/linuxbrew/.linuxbrew/Cellar/go/1.9.2/libexec/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc-5"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build399343442=/tmp/go-build -gno-record-gcc-switches"
CXX="g++-5"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

Maybe you don't install C compiler collectory?

Hi ! Thanks for your response !

Actually, I tracked it down to an issue with my LinuxBrew installation and the version of gcc it uses. After disabling it, it did built ok !

Hey, I am having a similar issue on linux mint 18. However I do not use Linux Brew. Could you please explain what you did to fix this issue ?

Never mind !! For me this problem was fixed with sudo apt-get install g++

I am on Mac and I can't build the code. My output for go env is the following

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mayukhsarkar/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mayukhsarkar/Documents/Golang"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/h4/5m8_frlx3y568n11bpfx6xz40000gn/T/go-build854985387=/tmp/go-build -gno-record-gcc-switches -fno-common"

and the error messages it throws

WORK=/var/folders/h4/5m8_frlx3y568n11bpfx6xz40000gn/T/go-build042584498
github.com/mattn/go-sqlite3
mkdir -p $WORK/b001/
cd /Users/mayukhsarkar/Documents/Golang/src/github.com/mattn/go-sqlite3
CGO_LDFLAGS='"-g" "-O2"' /usr/local/go/pkg/tool/darwin_amd64/cgo -objdir $WORK/b001/ -importpath github.com/mattn/go-sqlite3 -- -I $WORK/b001/ -g -O2 -std=gnu99 -DSQLITE_ENABLE_RTREE -DSQLITE_THREADSAFE=1 -DHAVE_USLEEP=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4_UNICODE61 -DSQLITE_TRACE_SIZE_LIMIT=15 -DSQLITE_OMIT_DEPRECATED -DSQLITE_DISABLE_INTRINSIC -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -Wno-deprecated-declarations -I/Users/mayukhsarkar/Documents/Golang/src/github.com/mattn/go-sqlite3 ./backup.go ./callback.go ./error.go ./sqlite3.go ./sqlite3_context.go ./sqlite3_load_extension.go ./sqlite3_opt_userauth_omit.go ./sqlite3_other.go ./sqlite3_type.go
# github.com/mattn/go-sqlite3
../github.com/mattn/go-sqlite3/backup.go:14:10: fatal error: 'stdlib.h' file not found
#include <stdlib.h>
         ^~~~~~~~~~
1 error generated.

I have also tried the following.

CC=clang
go get -v -x github.com/mattn/go-sqlite3

Please help. I am on Mac.

Never mind, I installed it. Turns out that my gcc installation was messed up. Fixed it using the following.

$ xcode-select --install

@MayukhSobo Only gcc should be used, even on Mac. The following works for my mac.

export CGO_ENABLED=1; export CC=gcc; go get -v -x github.com/mattn/go-sqlite3

Besides this comment, there is another solution for Mac users.

The root reason is due to a missing /usr/include directory.
Installing command-line tools (xcode-select --install), sometimes, will not automatically add it.
After installing command-line tools Install the package at:

# run this in Terminal
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

After that,
you should have a directory /usr/include with header files

From StackOverflow Answer.

talha131 solved my problem

Solution from @how2 works good. When i run my go app it shows this warning:

# command-line-arguments
clang: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]

How to hide the warning?

It happened after upgraded from Mojave to OSX Catalina. This does the trick to solve the warning before go get the package:

export SDKROOT=xcrun --show-sdk-path

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  ·  6Comments

tiaguinho picture tiaguinho  ·  3Comments

SaekiRaku picture SaekiRaku  ·  3Comments

hackertron picture hackertron  ·  10Comments

vzool picture vzool  ·  4Comments