go build error
yincongcyincong opened this issue · 25 comments
i use shell script to go build, but i failed
GOOS=linux GOARCH=386 go build && mv proxyWebApplication proxyWeb/proxyWebApplication && tar zcfv "zip/proxy-linux-386.tar.gz" proxyWeb
why?
this is error information
../github.com/mattn/go-sqlite3/sqlite3_go18.go:26: undefined: SQLiteConn ../github.com/mattn/go-sqlite3/sqlite3_go18.go:27: undefined: namedValue
my os is linux-amd64, only linux-amd64 can go build
Because you don't install cross C compiler for linux-i386.
Similar issue. Trying to compile for linux/x86_84 on my mac. Code will run on my hosting provider which doesn't have gcc installed. So I need to compile on my mac for use on linux.
$ GOOS=linux GOARCH=amd64 go build --tags "libsqlite3 linux"
# github.com/mattn/go-sqlite3
../github.com/mattn/go-sqlite3/sqlite3_go18.go:18:10: undefined: SQLiteConn
You must install cross C compiler for Linux on your Mac.
Any hints on installing that?
thanks
Nope. I just booted up a VirtualBox with the same OS as my hosting provider, installed go, etc, compiled, copied. works well. Took about 10m to download/install a CentOS6 VM. Another 10m to install/setup Go. Would have spent a lot longer figuring out cross-compile stuff.
Simillar problem here. I can not cross compile this library for linux/amd64 on macOS now.
Do you use cross C compiler? Maybe you are using host compiler. Check CC
in go env
.
@mattn Yes I was using the host compiler, it was the cause. So I installed the cross compiler for linux on mac: http://crossgcc.rts-software.org/doku.php?id=compiling_for_linux and ran the build command, the results was successful. (Of course, I did not run this output binary on linux instance yet)
Thank you.
@utdrmac I solved the cross compilation problem on mac with gcc for linux for mac
@mingrammer do you have gcc for linux for windows
@yincongcyincong I did not find one for windows. You should search it yourself, sorry.
While building this package for linux on OS X, I'm seeing following error. I tried everything you mentioned on the thread but nothing is working for me. Please let me know your thoughts on this.
(I'm using - GOOS=linux GOARCH=amd64)
../../../github.com/mattn/go-sqlite3/sqlite3_go18.go:18:10: undefined: SQLiteConn
With CGO_ENABLED=1
runtime/cgo
clang: warning: argument unused during compilation: '-pthread'
clang: warning: argument unused during compilation: '-gno-record-gcc-switches'
runtime/cgo
clang: warning: argument unused during compilation: '-pthread'
clang: warning: argument unused during compilation: '-gno-record-gcc-switches'
clang: warning: argument unused during compilation: '-nopie'
ld: unknown option: --build-id=none
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [dist/tapioca-httpd] Error 2
you need to use cross-C-compiler. you are doing:
compiling C source code for Linux on compiler that can generate Mac binary.
This should be:
compile C source code for Linux on compiler that can generate Linux binary.
So you need to set environment variable CC to the cross-C-compiler.
I tried as suggested but it is failing on the target linux server with following error.
I used cross compiler provided in http://crossgcc.rts-software.org/doku.php?id=compiling_for_linux
Error on linux server:
/lib64/libc.so.6: version `GLIBC_2.14' not found
Linux server has following installed:
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)
glibc-devel-2.12-1.166.el6.7.x86_64
@meeramn you obviously need to update your glibc package on the linux server to 2.14.
For those having this issue on linux (especially if you're using Ubuntu), please do the following:
$ sudo apt-get install gcc-mingw-w64
The above command will install cross compiler for C. Then you can build with the following code:
To build for windows amd64:
GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 go build -o binary_name_amd64.exe .
Similarly for windows 386:
GOOS=windows GOARCH=386 CC=i686-w64-mingw32-gcc CGO_ENABLED=1 go build -o binary_name_386.exe .
Hope this helps.
@mattn Can you suggest me some good cross compiler for mac on linux (Ubuntu 16.04)?. I came across a few that I found out on the internet which I listed below.
- https://github.com/tpoechtrager/osxcross
- https://launchpad.net/~flosoft/+archive/ubuntu/cross-apple (not sure whether this is good to use)
Thanks.
@bharath-srinivas sorry, I don't have Mac.
Does anyone have the correct incantation (or value for CC) to use the "cross compiler" on mac? I have gcc installed via brew but can't figure it out so I'm still getting this error, we could then improve the documentation by listing the actual steps required! The url in the page earlier linked is now extinct so it's of no use.
@utdrmac @mingrammer could you please write an update for the compilation section for MAC within the README. Hope you can take some time for it. I think it will help a lot of people. Don't have Mac myself.
@gjrtimmer Sorry, I gave up on using SQLite3 in my project because this was too complicated to cross-compile for each OS. I switched to https://github.com/coreos/bbolt in my project which is 100% Go and allows me to compile for each os/arch on my mac.
For those having this issue on linux (especially if you're using Ubuntu), please do the following:
$ sudo apt-get install gcc-mingw-w64The above command will install cross compiler for C. Then you can build with the following code:
To build for windows amd64:
GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 go build -o binary_name_amd64.exe .
Similarly for windows 386:
GOOS=windows GOARCH=386 CC=i686-w64-mingw32-gcc CGO_ENABLED=1 go build -o binary_name_386.exe .
Hope this helps.
here new problem is "i686-w64-mingw32-gcc: error: CreateProcess: No such file or directory", how to resolve?