Cross platform build failed
elgs opened this issue · 68 comments
When I tried to build from OS X for Linux, it says:
$ GOOS=linux GOARCH=amd64 go install
# github.com/mattn/go-sqlite3
../../../mattn/go-sqlite3/sqlite3.c:241 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:256 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:296 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:309 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:339 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:342 unknown #: elif
../../../mattn/go-sqlite3/sqlite3.c:343 macro redefined: SQLITE_INT_TO_PTR
../../../mattn/go-sqlite3/sqlite3.c:344 macro redefined: SQLITE_PTR_TO_INT
../../../mattn/go-sqlite3/sqlite3.c:345 unknown #: elif
../../../mattn/go-sqlite3/sqlite3.c:346 macro redefined: SQLITE_INT_TO_PTR
../../../mattn/go-sqlite3/sqlite3.c:347 macro redefined: SQLITE_PTR_TO_INT
too many errors
try to set CC=clang or CC=gcc
On 1/29/14, elgs notifications@github.com wrote:
When I tried to build from OS X for Linux, it says:
$ GOOS=linux GOARCH=amd64 go installgithub.com/mattn/go-sqlite3
../../../mattn/go-sqlite3/sqlite3.c:241 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:256 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:296 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:309 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:339 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:342 unknown #: elif
../../../mattn/go-sqlite3/sqlite3.c:343 macro redefined: SQLITE_INT_TO_PTR
../../../mattn/go-sqlite3/sqlite3.c:344 macro redefined: SQLITE_PTR_TO_INT
../../../mattn/go-sqlite3/sqlite3.c:345 unknown #: elif
../../../mattn/go-sqlite3/sqlite3.c:346 macro redefined: SQLITE_INT_TO_PTR
../../../mattn/go-sqlite3/sqlite3.c:347 macro redefined: SQLITE_PTR_TO_INT
too many errors
Reply to this email directly or view it on GitHub:
#106
- Yasuhiro Matsumoto
Seems to be the same:
$ CC=clang GOOS=linux GOARCH=amd64 go install
# github.com/mattn/go-sqlite3
../../../mattn/go-sqlite3/sqlite3.c:241 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:256 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:296 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:309 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:339 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:342 unknown #: elif
../../../mattn/go-sqlite3/sqlite3.c:343 macro redefined: SQLITE_INT_TO_PTR
../../../mattn/go-sqlite3/sqlite3.c:344 macro redefined: SQLITE_PTR_TO_INT
../../../mattn/go-sqlite3/sqlite3.c:345 unknown #: elif
../../../mattn/go-sqlite3/sqlite3.c:346 macro redefined: SQLITE_INT_TO_PTR
../../../mattn/go-sqlite3/sqlite3.c:347 macro redefined: SQLITE_PTR_TO_INT
too many errors
108:gsyncd elgs$ CC=gcc GOOS=linux GOARCH=amd64 go install
# github.com/mattn/go-sqlite3
../../../mattn/go-sqlite3/sqlite3.c:241 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:256 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:296 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:309 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:339 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:342 unknown #: elif
../../../mattn/go-sqlite3/sqlite3.c:343 macro redefined: SQLITE_INT_TO_PTR
../../../mattn/go-sqlite3/sqlite3.c:344 macro redefined: SQLITE_PTR_TO_INT
../../../mattn/go-sqlite3/sqlite3.c:345 unknown #: elif
../../../mattn/go-sqlite3/sqlite3.c:346 macro redefined: SQLITE_INT_TO_PTR
../../../mattn/go-sqlite3/sqlite3.c:347 macro redefined: SQLITE_PTR_TO_INT
too many errors
The same happens for me. I am using an amd64 linux and trying to compile for windows, os x and freebsd. All of them fail with the same message.
$ GOOS=windows GOARCH=amd64 go install
# github.com/mattn/go-sqlite3
./sqlite3.c:241 unknown #: if
./sqlite3.c:256 unknown #: if
./sqlite3.c:296 unknown #: if
./sqlite3.c:309 unknown #: if
./sqlite3.c:339 unknown #: if
./sqlite3.c:342 unknown #: elif
./sqlite3.c:343 macro redefined: SQLITE_INT_TO_PTR
./sqlite3.c:344 macro redefined: SQLITE_PTR_TO_INT
./sqlite3.c:345 unknown #: elif
./sqlite3.c:346 macro redefined: SQLITE_INT_TO_PTR
./sqlite3.c:347 macro redefined: SQLITE_PTR_TO_INT
too many errors
$ GOOS=darwin GOARCH=amd64 go install
# github.com/mattn/go-sqlite3
./sqlite3.c:241 unknown #: if
./sqlite3.c:256 unknown #: if
./sqlite3.c:296 unknown #: if
./sqlite3.c:309 unknown #: if
./sqlite3.c:339 unknown #: if
./sqlite3.c:342 unknown #: elif
./sqlite3.c:343 macro redefined: SQLITE_INT_TO_PTR
./sqlite3.c:344 macro redefined: SQLITE_PTR_TO_INT
./sqlite3.c:345 unknown #: elif
./sqlite3.c:346 macro redefined: SQLITE_INT_TO_PTR
./sqlite3.c:347 macro redefined: SQLITE_PTR_TO_INT
too many errors
$ GOOS=freebsd GOARCH=amd64 go install
# github.com/mattn/go-sqlite3
./sqlite3.c:241 unknown #: if
./sqlite3.c:256 unknown #: if
./sqlite3.c:296 unknown #: if
./sqlite3.c:309 unknown #: if
./sqlite3.c:339 unknown #: if
./sqlite3.c:342 unknown #: elif
./sqlite3.c:343 macro redefined: SQLITE_INT_TO_PTR
./sqlite3.c:344 macro redefined: SQLITE_PTR_TO_INT
./sqlite3.c:345 unknown #: elif
./sqlite3.c:346 macro redefined: SQLITE_INT_TO_PTR
./sqlite3.c:347 macro redefined: SQLITE_PTR_TO_INT
too many errors
I've tried CC=gcc
and CC=clang
. Nothing changes.
Could you please try GOOS=linux GOARCH=amd64 go install -x
?
Still no luck.
$ go version
go version go1.2 darwin/amd64
32:gsyncd elgs$ GOOS=linux GOARCH=amd64 go -x install
flag provided but not defined: -x
Go is a tool for managing Go source code.
Usage:
go command [arguments]
The commands are:
build compile packages and dependencies
clean remove object files
env print Go environment information
fix run go tool fix on packages
fmt run gofmt on package sources
get download and install packages and dependencies
install compile and install packages and dependencies
list list packages
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet run go tool vet on packages
Use "go help [command]" for more information about a command.
Additional help topics:
c calling between Go and C
gopath GOPATH environment variable
importpath import path syntax
packages description of package lists
testflag description of testing flags
testfunc description of testing functions
Use "go help [topic]" for more information about that topic.
It must be GOOS=linux GOARCH=amd64 go install -x
with the -x
after install
. I think that $CC
does nothing for go. When I use it it still uses go's 6c. Example:
$ CC=gcc GOOS=windows GOARCH=amd64 go install -x
WORK=/tmp/go-build504111402
mkdir -p $WORK/github.com/mattn/go-sqlite3/_obj/
mkdir -p $WORK/github.com/mattn/
cd /home/iron4o/gopath/src/github.com/mattn/go-sqlite3
/home/iron4o/go/pkg/tool/linux_amd64/6c -F -V -w -I $WORK/github.com/mattn/go-sqlite3/_obj/ -I /home/iron4o/go/pkg/windows_amd64 -o $WORK/github.com/mattn/go-sqlite3/_obj/sqlite3.6 -D GOOS_windows -D GOARCH_amd64 ./sqlite3.c
# github.com/mattn/go-sqlite3
./sqlite3.c:241 unknown #: if
./sqlite3.c:256 unknown #: if
./sqlite3.c:296 unknown #: if
./sqlite3.c:309 unknown #: if
./sqlite3.c:339 unknown #: if
./sqlite3.c:342 unknown #: elif
./sqlite3.c:343 macro redefined: SQLITE_INT_TO_PTR
./sqlite3.c:344 macro redefined: SQLITE_PTR_TO_INT
./sqlite3.c:345 unknown #: elif
./sqlite3.c:346 macro redefined: SQLITE_INT_TO_PTR
./sqlite3.c:347 macro redefined: SQLITE_PTR_TO_INT
too many errors
Also, I've found this https://code.google.com/p/go/issues/detail?id=4714 . Seems like it is on the subject. CGO_ENABLED is forcefully set to 0 when corss compiling for some reason.
Thanks @ironsmile, this time I got some more error messages:
$ GOOS=linux GOARCH=amd64 go install -x
WORK=/var/folders/lj/l5w0rd_j1vs9wdv438r9m96h0000gn/T/go-build265592758
mkdir -p $WORK/github.com/elgs/gsyncd/index/_obj/
mkdir -p $WORK/github.com/elgs/gsyncd/
cd /Volumes/User/Home/Dev/Go/gsyncd/src/github.com/elgs/gsyncd/index
/usr/local/Cellar/go/1.2/libexec/pkg/tool/darwin_amd64/6g -o $WORK/github.com/elgs/gsyncd/index/_obj/_go_.6 -p github.com/elgs/gsyncd/index -complete -D _/Volumes/User/Home/Dev/Go/gsyncd/src/github.com/elgs/gsyncd/index -I $WORK -I /Volumes/User/Home/Dev/Go/gsyncd/pkg/linux_amd64 ./index.go
mkdir -p $WORK/github.com/mattn/go-sqlite3/_obj/
mkdir -p $WORK/github.com/mattn/
cd /Volumes/User/Home/Dev/Go/gsyncd/src/github.com/mattn/go-sqlite3
/usr/local/Cellar/go/1.2/libexec/pkg/tool/darwin_amd64/6c -F -V -w -I $WORK/github.com/mattn/go-sqlite3/_obj/ -I /usr/local/Cellar/go/1.2/libexec/pkg/linux_amd64 -o $WORK/github.com/mattn/go-sqlite3/_obj/sqlite3.6 -D GOOS_linux -D GOARCH_amd64 ./sqlite3.c
# github.com/mattn/go-sqlite3
../../../mattn/go-sqlite3/sqlite3.c:241 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:256 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:296 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:309 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:339 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:342 unknown #: elif
../../../mattn/go-sqlite3/sqlite3.c:343 macro redefined: SQLITE_INT_TO_PTR
../../../mattn/go-sqlite3/sqlite3.c:344 macro redefined: SQLITE_PTR_TO_INT
../../../mattn/go-sqlite3/sqlite3.c:345 unknown #: elif
../../../mattn/go-sqlite3/sqlite3.c:346 macro redefined: SQLITE_INT_TO_PTR
../../../mattn/go-sqlite3/sqlite3.c:347 macro redefined: SQLITE_PTR_TO_INT
too many errors
cd /Volumes/User/Home/Dev/Go/gsyncd/src/github.com/elgs/gsyncd/index
/usr/local/Cellar/go/1.2/libexec/pkg/tool/darwin_amd64/pack grcP $WORK $WORK/github.com/elgs/gsyncd/index.a $WORK/github.com/elgs/gsyncd/index/_obj/_go_.6
mkdir -p /Volumes/User/Home/Dev/Go/gsyncd/pkg/linux_amd64/github.com/elgs/gsyncd/
cp $WORK/github.com/elgs/gsyncd/index.a /Volumes/User/Home/Dev/Go/gsyncd/pkg/linux_amd64/github.com/elgs/gsyncd/index.a
Now I'm wondering if it is not possible to do cross platform compile as it contains c program, so it is not in pure go?
Well It seems it is exactly that. For example when building for my native machine with CGO_ENABLED=0
I did get the same message:
$ CGO_ENABLED=0 go install -x
WORK=/tmp/go-build159155876
mkdir -p $WORK/github.com/mattn/go-sqlite3/_obj/
mkdir -p $WORK/github.com/mattn/
cd /home/iron4o/gopath/src/github.com/mattn/go-sqlite3
/home/iron4o/go/pkg/tool/linux_amd64/6c -F -V -w -I $WORK/github.com/mattn/go-sqlite3/_obj/ -I /home/iron4o/go/pkg/linux_amd64 -o $WORK/github.com/mattn/go-sqlite3/_obj/sqlite3.6 -D GOOS_linux -D GOARCH_amd64 ./sqlite3.c
# github.com/mattn/go-sqlite3
./sqlite3.c:241 unknown #: if
./sqlite3.c:256 unknown #: if
./sqlite3.c:296 unknown #: if
./sqlite3.c:309 unknown #: if
./sqlite3.c:339 unknown #: if
./sqlite3.c:342 unknown #: elif
./sqlite3.c:343 macro redefined: SQLITE_INT_TO_PTR
./sqlite3.c:344 macro redefined: SQLITE_PTR_TO_INT
./sqlite3.c:345 unknown #: elif
./sqlite3.c:346 macro redefined: SQLITE_INT_TO_PTR
./sqlite3.c:347 macro redefined: SQLITE_PTR_TO_INT
too many errors
On the other hand when I try to cross compile with CGO_ENABLED=1
I got the hardcoded message
$ CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go install -x
WORK=/tmp/go-build587075426
mkdir -p $WORK/runtime/cgo/_obj/
mkdir -p $WORK/runtime/
go build runtime/cgo: cannot use cgo when compiling for a different operating system
You can find it in the go build tool source:
[~/go/src]
iron4o$ search 'cannot use cgo when compiling for a different operating system'
cmd/go/build.go- if goos != toolGOOS {
cmd/go/build.go: return nil, nil, errors.New("cannot use cgo when compiling for a different operating system")
cmd/go/build.go- }
I am thinking of removing this and rebuilding my go tools :D But that will be left for later.
@ironsmile WOW, what a hack you are going to do!
Now I think it's reasonable that by the nature of C, it might be not that easy to compile a Windows executable from a Mac, or Linux.
Yeah I'm also having the same issue... nothing seems to be working. I tried this
https://gist.github.com/steeve/6905542 and it still didn't compile.
Having the same issue with cross-building on osx for linux amd64
I'm having a similar issues trying to cross-compile a windows executable from a 32-bit debian machine:
# github.com/mattn/go-sqlite3
../../mattn/go-sqlite3/sqlite3.c:92 unknown #: if
../../mattn/go-sqlite3/sqlite3.c:94 6c: No such file or directory: mingw.h
# github.com/mattn/go-sqlite3
../../mattn/go-sqlite3/sqlite3.c:92 unknown #: if
../../mattn/go-sqlite3/sqlite3.c:94 8c: No such file or directory: mingw.h
Looks to me like it's searching for a hardcoded mingw header file.
@mattn, sorry for a late reply. Yes. I'm compiling windows executable. Finally I was able to compile both win32 and win64 executables from mingw32, but with mingw64, I can only compile win64 executable.
As reported here
https://groups.google.com/forum/#!topic/golang-nuts/0pm23TkuCKQ
cgo is disabled on cross-compilation :(
Relevant Go issue: https://code.google.com/p/go/issues/detail?id=4714
CL57100043 was merged. Still have problem?
Retrying with HEAD
@mattn I'm sorry I have wiped out my mingw64 environment as building that windows executable was a one off thing last time. I will try to reproduce the same problem again and come back here with my update.
NP :)
Hello!
I have the same problem that @jordan-wright had, have you been able to fix it?
I am trying to build my project here: http://gobuild.io/build/github.com/agonzalezro/polo (darwin/amd64) but I get this output:
...
github.com/mattn/go-sqlite3
# github.com/mattn/go-sqlite3
../../mattn/go-sqlite3/sqlite3.c:92 unknown #: if
../../mattn/go-sqlite3/sqlite3.c:94 6c: No such file or directory: mingw.h
[golang-sh]$ echo cleaning...
cleaning...
exit status 2
I will be happy to provide any more information than you need or do any other test, but "sadly", I am going to be disconnected for few days (sorry in advance).
Thanks!
Adding to this, I see the same when trying to compile for 32 bits on 64 bit Linux (not trying to cross compile to another OS, although that would be nice too);
jb@udev2:~ $ go get github.com/mattn/go-sqlite3
jb@udev2:~ $ GOARCH=386 go get github.com/mattn/go-sqlite3
# github.com/mattn/go-sqlite3
src/github.com/mattn/go-sqlite3/sqlite3.c:92 unknown #: if
src/github.com/mattn/go-sqlite3/sqlite3.c:94 8c: No such file or directory: mingw.h
jb@udev2:~ $ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jb"
GORACE=""
GOROOT="/home/jb/go"
GOTOOLDIR="/home/jb/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
jb@udev2:~ $
As the fix under https://code.google.com/p/go/issues/detail?id=4714 should be now in the 1.3 release, is there any chance to get cross compilation working?
With Go 1.3 I'm getting ATM:
go build github.com/mattn/go-sqlite3: no buildable Go source files in /Users/marc/dev/go/src/github.com/mattn/go-sqlite3
I'm on OS X and trying to build for ARM
GOARCH=arm GOARM=6 GOOS=linux go build main.go
@mattn
Hello !
I have the same problem that @marcboeker had, have you been able to fix it?
@mattn
Hello !
I'm on XP and trying to build for LINUX With Go 1.3
get problem
github.com/mattn/go-sqlite3
d:\go\go\src\pkg\github.com\mattn\go-sqlite3\sqlite3.c:92 unknown #: if
d:\go\go\src\pkg\github.com\mattn\go-sqlite3\sqlite3.c:94 8c: No such file or directory: mingw.h
tanks
Use goxc. And cross-compilable C compiler.
change to goxc ,it is work good---A simple example is good work,BUT +go-sqlite3 I get
\sqlite3.c:92 unknown #: if sqlite3.c:94 8c: No such file or directory: mingw.h
ubunto1404 +go1.3
sudo apt-get install git
sudo apt-get install mercurial
sudo apt-get install mingw32 mingw32-binutils mingw32-runtime
go get github.com/laher/goxc
goxc -t
I've tried it also with goxc, but had no luck on my Mac.
# github.com/mattn/go-sqlite3
~/go/src/github.com/mattn/go-sqlite3/sqlite3.c:92 unknown #: if
~/go/src/github.com/mattn/go-sqlite3/sqlite3.c:94 5c: No such file or directory: mingw.h
[goxc:xc] 2014/07/19 09:03:14 'go' returned error: exit status 2
[goxc:xc] 2014/07/19 09:03:14 Error: exit status 2
@kc87654321 Are you using gc or gccgo as a compiler? Could you please post your command including all the args you are using? Thanks
change to goxc ,it is work good---A simple example is good work,BUT +go-sqlite3 I get
\sqlite3.c:92 unknown #: if sqlite3.c:94 8c: No such file or directory: mingw.h
ubunto1404 +go1.3
sudo apt-get install git
sudo apt-get install mercurial
sudo apt-get install mingw32 mingw32-binutils mingw32-runtime
go get github.com/laher/goxc
goxc -t
As I wrote, please use cross compiler.
On 7/20/14, kc87654321 notifications@github.com wrote:
change to goxc ,it is work good---A simple example is good work,BUT
+go-sqlite3 I get
\sqlite3.c:92 unknown #: if sqlite3.c:94 8c: No such file or directory:
mingw.h
ubunto1404 +go1.3
sudo apt-get install git
sudo apt-get install mercurial
sudo apt-get install mingw32 mingw32-binutils mingw32-runtime
go get github.com/laher/goxc
goxc -t
Reply to this email directly or view it on GitHub:
#106 (comment)
- Yasuhiro Matsumoto
With CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go install -x
I get
WORK=/var/folders/wq/yqhb4nvd0ln8wk65d4689kmw0000gn/T/go-build414777899
mkdir -p $WORK/runtime/cgo/_obj/
mkdir -p $WORK/runtime/
cd /usr/local/Cellar/go/1.3/libexec/src/pkg/runtime/cgo
CGO_LDFLAGS="-g" "-O2" "-lpthread" /usr/local/Cellar/go/1.3/libexec/pkg/tool/darwin_amd64/cgo - objdir $WORK/runtime/cgo/_obj/ -import_runtime_cgo=false -import_syscall=false -- -I $WORK/runtime/cgo/_obj/ -Wall -Werror cgo.go
# runtime/cgo
clang: error: argument unused during compilation: '-mno-thumb'
And with CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=6 go install -x
I get
WORK=/var/folders/wq/yqhb4nvd0ln8wk65d4689kmw0000gn/T/go-build807610085
mkdir -p $WORK/github.com/mattn/go-sqlite3/_obj/
mkdir -p $WORK/github.com/mattn/
cd /Users/marc/Temp/go/src/github.com/mattn/go-sqlite3
/usr/local/Cellar/go/1.3/libexec/pkg/tool/darwin_amd64/5g -o $WORK/github.com/mattn/go-sqlite3.a -trimpath $WORK -p github.com/mattn/go-sqlite3 -D _/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3 -I $WORK -pack ./doc.go
/usr/local/Cellar/go/1.3/libexec/pkg/tool/darwin_amd64/5c -F -V -w -trimpath $WORK -I $WORK/github.com/mattn/go-sqlite3/_obj/ -I /usr/local/Cellar/go/1.3/libexec/pkg/linux_arm -o $WORK/github.com/mattn/go-sqlite3/_obj/sqlite3.5 -D GOOS_linux -D GOARCH_arm ./sqlite3.c
# github.com/mattn/go-sqlite3
/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3/sqlite3.c:92 unknown #: if
/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3/sqlite3.c:94 5c: No such file or directory: mingw.h
And goxc -arch arm -bc arm -os linux -d=/Users/marc/Desktop
gives me
# github.com/mattn/go-sqlite3
/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3/sqlite3.c:92 unknown #: if
/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3/sqlite3.c:94 5c: No such file or directory: mingw.h
[goxc:xc] 2014/08/01 23:31:13 'go' returned error: exit status 2
[goxc:xc] 2014/08/01 23:31:13 Error: exit status 2
[goxc:xc] 2014/08/01 23:31:13 Have you run `goxc -t` for this platform (arm,linux)???
[goxc:xc] 2014/08/01 23:31:13 Multiple errors (returning first one): [exit status 2]
[goxc:xc] 2014/08/01 23:31:13 Stopping after 'xc' failed with error 'exit status 2'
[goxc] 2014/08/01 23:31:13 RunTasks returned error exit status 2
Looks like the header file points to the wrong path oder my environment is screwed up...
please use cross compiler.
On 8/2/14, Marc Boeker notifications@github.com wrote:
With
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go install -x
I getWORK=/var/folders/wq/yqhb4nvd0ln8wk65d4689kmw0000gn/T/go-build414777899 mkdir -p $WORK/runtime/cgo/_obj/ mkdir -p $WORK/runtime/ cd /usr/local/Cellar/go/1.3/libexec/src/pkg/runtime/cgo CGO_LDFLAGS="-g" "-O2" "-lpthread"
/usr/local/Cellar/go/1.3/libexec/pkg/tool/darwin_amd64/cgo - objdir
$WORK/runtime/cgo/_obj/ -import_runtime_cgo=false -import_syscall=false --
-I $WORK/runtime/cgo/_obj/ -Wall -Werror cgo.go
# runtime/cgo
clang: error: argument unused during compilation: '-mno-thumb'And with
CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=6 go install -x
I getWORK=/var/folders/wq/yqhb4nvd0ln8wk65d4689kmw0000gn/T/go-build807610085 mkdir -p $WORK/github.com/mattn/go-sqlite3/_obj/ mkdir -p $WORK/github.com/mattn/ cd /Users/marc/Temp/go/src/github.com/mattn/go-sqlite3 /usr/local/Cellar/go/1.3/libexec/pkg/tool/darwin_amd64/5g -o
$WORK/github.com/mattn/go-sqlite3.a -trimpath $WORK -p
github.com/mattn/go-sqlite3 -D
_/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3 -I $WORK -pack
./doc.go
/usr/local/Cellar/go/1.3/libexec/pkg/tool/darwin_amd64/5c -F -V -w
-trimpath $WORK -I $WORK/github.com/mattn/go-sqlite3/_obj/ -I
/usr/local/Cellar/go/1.3/libexec/pkg/linux_arm -o
$WORK/github.com/mattn/go-sqlite3/_obj/sqlite3.5 -D GOOS_linux -D GOARCH_arm
./sqlite3.c
# github.com/mattn/go-sqlite3
/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3/sqlite3.c:92 unknown
#: if
/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3/sqlite3.c:94 5c: No
such file or directory: mingw.hAnd
goxc -arch arm -bc arm -os linux -d=/Users/marc/Desktop
gives me# github.com/mattn/go-sqlite3 /Users/marc/Temp/go/src/github.com/mattn/go-sqlite3/sqlite3.c:92 unknown
#: if
/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3/sqlite3.c:94 5c: No
such file or directory: mingw.h
[goxc:xc] 2014/08/01 23:31:13 'go' returned error: exit status 2
[goxc:xc] 2014/08/01 23:31:13 Error: exit status 2
[goxc:xc] 2014/08/01 23:31:13 Have you rungoxc -t
for this platform
(arm,linux)???
[goxc:xc] 2014/08/01 23:31:13 Multiple errors (returning first one):
[exit status 2]
[goxc:xc] 2014/08/01 23:31:13 Stopping after 'xc' failed with error
'exit status 2'
[goxc] 2014/08/01 23:31:13 RunTasks returned error exit status 2Looks like the header file points to the wrong path oder my environment is
screwed up...
Reply to this email directly or view it on GitHub:
#106 (comment)
- Yasuhiro Matsumoto
I've tought, that goxc
helps me to cross compile?
Could you please give me a short example on how to cross compile go-sqlite3 for the Raspberry Pi. That would be great. Thanks!
I think GOXC haove bug ,
than i get sqlite run in the Raspberry Pi,the Raspberry Pi need install golong, than it is good work.
if use GOXC,get many erro.
cross compiler--i thank ,it is nogood ider for no officegolanglib.
it you need go-sqlite3 work in ARM567,than use golang in the Raspberry.
You need to use cross compiler with CC_FOR_TARGET environment variable.
See http://golang.org/cmd/cgo/#hdr-Using_cgo_with_the_go_command
mattn, i'm having the same issue:
doing darwin -> linux/amd64
so if it were you, would you try something like this with goxc ?
CC_FOR_TARGET=gcc goxc ?
Yes, but you need to specify cross-platform-compiler instead of system-gcc.
I can't get it working, even not with an ARM GCC
CC_FOR_TARGET=arm-none-eabi-gcc GOOS=linux GOARCH=arm GOARM=6 go build main.go
# github.com/mattn/go-sqlite3
/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3/sqlite3.c:92 unknown #: if
/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3/sqlite3.c:94 5c: No such file or directory: mingw.h
Version:
$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.8.4 20140725 (release) [ARM/embedded-4_8-branch revision 213147]
@mattn Could you please give me an example commandline to compile it? Thanks.
Count you try this?
$ cat > foo.c
#include <mingw.h>
int main() {}
^D
$ arm-none-eabi-gcc foo.c
Your arm-c compiler seems having _HAVE_MINGW_H
$ arm-none-eabi-gcc foo.c
foo.c:1:19: fatal error: mingw.h: No such file or directory
#include <mingw.h>
^
compilation terminated.
I'm running OS X 10.10.
Is there a way to tell gcc to not define _HAVE_MINGW_H
or _HAVE__MINGW_H
?
#if defined(_HAVE_MINGW_H)
# include "mingw.h"
#elif defined(_HAVE__MINGW_H)
# include "_mingw.h"
#endif
I don't understand, why GOOS=linux
triggers the include of mingw on my Mac?
$ GOOS=linux go build main.go
# github.com/mattn/go-sqlite3
/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3/sqlite3.c:92 unknown #: if
/Users/marc/Temp/go/src/github.com/mattn/go-sqlite3/sqlite3.c:94 6c: No such file or directory: mingw.h
vs.
$ GOOS=darwin go build main.go
[success]
Thanks
Hey guys!
I have same problem with gcc and gocx. I don't have impressive experience with compiled languages and i hope that you can tell me what wrongs.
I've setup this package by "go get" and just include it to my source.
When i try compile it by "goxc" i get "../github.com/mattn/go-sqlite3/sqlite3.c:94 8c: No such file or directory: mingw.h".
@mattn you mentioned cross compiler, what is it? How i can install it and using? Why i've get this error message for all platforms exclude my host platform?
Thank you.
And if i run "GOOS=linux GOARCH=amd64 go build" complier works properly. I've got binary file.
But if i change GOARCH to 386 i've got the same problem related with mingw.h.
Okay, after 10 hours of researches i can do it with this link: http://www.limitlessfx.com/cross-compile-golang-app-for-windows-from-linux.html
@marcboeker I was struggling with cross-compiling for raspberry pi as well. I ended up biting the bullet and installing Go on the RPi using http://dave.cheney.net/unofficial-arm-tarballs and compiling natively. Make sure you set VRAM to around 16 so compilation doesn't take forever!
@imheresamir Thanks for the hint. Yeah, that's exactly what I'm doing at the moment and it is so slow :) But I'm going to try the VRAM option, hopefully this speeds things up. Thanks!
@Smile42RU Thanks great post about cross compiling.
I've add link to you post on README.md
Thanks all!
Did anyone ever get this to cross-compile to Linux from a Mac OS X?
Nope, unfortunately not :(
I'm using a second, dedicated Raspberry Pi to do the job.
@marcboeker I've had good luck using karalabe/xgo to cross-compile go-sqlite3 for ARM devices. Uses a docker linux container, but should be a lot faster than an RPi.
@hasty Awesome, thanks for the tip!
Hi, this is how I cross compile binary for freescale/arm on i386 architecture:
CC=/tools/m1sdk-tiny-1.0.0/toolchain/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin/arm-linux-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm go build main.go
Thanks!
I have the same problem on osx, attempting to build linux/amd64 version for my program.
ld: unknown option: --build-id=none
clang: error: linker command failed with exit code 1 (use -v to see invocation)
try with export CC=gcc
.
@mattn Hello,
$ CC=gcc-4.9 GOOS=linux GOARCH=amd64 CGO_ENABLED=1 godep go build 1 ↵ (go1.5.2 node@v5.0.0)
# runtime/cgo
gcc-4.9: warning: couldn't understand kern.osversion '14.3.0
# runtime/cgo
gcc-4.9: warning: couldn't understand kern.osversion '14.3.0
# runtime/cgo
gcc-4.9: warning: couldn't understand kern.osversion '14.3.0
/Users/hit9/github/oo/go/src/runtime/cgo/cgo.go:52:19: fatal error: errno.h: No such file or directory
compilation terminated.
godep: go exit status 2
are you doing cross-compiling? when you need to use cross-compiler not host-compiler.
Ran into similar issue cross-compiling a linux binary on osx. Near as I can tell in my mini investigation, cross-compiling would work except that osx's implementation of the linker tool (ld
) doesn't understand the --build-id=none
flag, which is where it chokes. Both gcc
and clang
attempt to pass this flag along to ld
regardless of what you do with the CC
, GCO_ENABLED
, etc environment variables, so it's simply not gonna work.
I have a simple work around using docker which will hopefully help others who don't want to go through the trouble of recompiling a linux version of ld
for osx:
Note: Naturally a docker workaround will require that you have docker installed :)
@mattn If you think it's reasonable feel free to add it to your readme where it will be more visible. I can make a PR as well if you like.
docker run --rm -v $GOPATH:/go -w /go/src/path/to/app golang:latest go build -v
This will put your executable in the expected place, in this case, $GOPATH/src/path/to/app
.
You just need to update that /go/src/path/to/app
part to be your actual directory containing your app, for example, /go/src/path/github.com/username/awesomeSqliteApp
If you want this working in a script like I have (for example I use a python fabric script to build and deploy automatically), you can do the following to prep docker on osx, since otherwise it requires the "Docker Quickstart Terminal":
eval $(docker-machine env default)
docker run --rm -v $GOPATH:/go -w /go/src/path/to/app golang:latest go build -v
In theory this should work on any platform that can run docker, though I've only tried on osx.
@jeffbmartinez Thanks. Using docker is one of the way to do cross-compiling. So it's useful. If possible, could you please send me pull-request to update README.md?
Leaving this comment in the hopes it helps someone else in 2016.
Cross compiling Linux (Debian Jessie amd64) -> Windows (amd64) and OSX (amd64) worked for me with the following:
To Windows:
apt-get install gcc_mingw64
env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build $appname
To OSX:
Follow instructions at https://github.com/tpoechtrager/osxcross to build apple cross compiler
env CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC=o64-clang go build $appname
@cprevallet Thank you, (ubuntu)work for windows.
apt-get install gcc-mingw-w64
for documentation purposes:
in order to cross compile 32bit ubuntu on a 64bit ubuntu system libc6-dev-i386
is required.
Setting CC="gcc -m32"
works.
@jeffbmartinez use docker run --rm with sqlite3 , i cannot build , sth is wrong , go build -v is nothing with hold..
Thanks @jeffbmartinez, it got me on the right track to get cross compilation working for Raspberry Pi 3. In case it's useful for anyone else, here's the Dockerfile I'm using for OSX:
FROM dockcross/linux-armv7:latest
# Largely copied from the official Golang image Dockerfile
RUN set -eux; \
wget -O go.tgz "https://golang.org/dl/go1.9.1.linux-amd64.tar.gz"; \
tar -C /usr/local -xzf go.tgz; \
rm go.tgz; \
export PATH="/usr/local/go/bin:$PATH"; \
go version
ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
WORKDIR $GOPATH
And the command to build a package from the package directory:
PWD=$(pwd)
PROJECT="/go${PWD/"$GOPATH"/}"
docker run --rm -v $GOPATH:/go -w $PROJECT \
-e "CGO_ENABLED=1" -e "GOARCH=arm" \
go-arm-linux:latest go build .
After some searching, I found a way to cross compilation on OSX:
- Install cross-compiler toolchains
brew install FiloSottile/musl-cross/musl-cross
brew install mingw-w64
- Build with
-ldflags "-linkmode external -extldflags -static"
Ex:
GOOS=linux GOARCH=amd64 CC="/usr/local/bin/x86_64-linux-musl-gcc" CGO_ENABLED=1 go build -ldflags "-linkmode external -extldflags -static" -o [OUTPUT_BINARY]
Reference: https://blog.filippo.io/easy-windows-and-linux-cross-compilers-for-macos/