Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go build error #491

Closed
yincongcyincong opened this issue Nov 22, 2017 · 26 comments
Closed

go build error #491

yincongcyincong opened this issue Nov 22, 2017 · 26 comments

Comments

@yincongcyincong
Copy link

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

@yincongcyincong
Copy link
Author

my os is linux-amd64, only linux-amd64 can go build

@mattn
Copy link
Owner

mattn commented Nov 22, 2017

Because you don't install cross C compiler for linux-i386.

@utdrmac
Copy link

utdrmac commented Nov 24, 2017

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

@mattn
Copy link
Owner

mattn commented Nov 24, 2017

You must install cross C compiler for Linux on your Mac.

@utdrmac
Copy link

utdrmac commented Nov 24, 2017

Any hints on installing that?

@yincongcyincong
Copy link
Author

thanks

@mattn
Copy link
Owner

mattn commented Nov 25, 2017

@utdrmac I don't have Mac. Sorry.

@manojm321
Copy link

@utdrmac Were able to compile linux binary on mac?

@utdrmac
Copy link

utdrmac commented Nov 27, 2017

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.

@mingrammer
Copy link

mingrammer commented Dec 1, 2017

Simillar problem here. I can not cross compile this library for linux/amd64 on macOS now.

@mattn
Copy link
Owner

mattn commented Dec 1, 2017

Do you use cross C compiler? Maybe you are using host compiler. Check CC in go env.

@mingrammer
Copy link

mingrammer commented Dec 1, 2017

@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

@yincongcyincong
Copy link
Author

@mingrammer do you have gcc for linux for windows

@mingrammer
Copy link

mingrammer commented Dec 5, 2017

@yincongcyincong I did not find one for windows. You should search it yourself, sorry.

@meeramn
Copy link

meeramn commented Jan 23, 2018

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

@mattn
Copy link
Owner

mattn commented Jan 23, 2018

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.

@meeramn
Copy link

meeramn commented Jan 23, 2018

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

@utdrmac
Copy link

utdrmac commented Jan 23, 2018

@meeramn you obviously need to update your glibc package on the linux server to 2.14.

@bharath-srinivas
Copy link

bharath-srinivas commented Jan 29, 2018

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.

@bharath-srinivas
Copy link

@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.

Thanks.

@mattn
Copy link
Owner

mattn commented Jan 30, 2018

@bharath-srinivas sorry, I don't have Mac.

gjrtimmer added a commit to gjrtimmer/go-sqlite3 that referenced this issue May 26, 2018
Compile Section Closes mattn#175
Compile Section Closes mattn#201
Compile Section Closes mattn#206
Compile Section Closes mattn#404
Compile Section Closes mattn#217
Compile Section Closes mattn#224
Compile Section Closes mattn#234
Compile Section Closes mattn#242
Feature table Closes mattn#255
Description Section Closes mattn#232
Golang:1.6 not supported Closes mattn#272
Golang:1.5 not supported + compilation section Closes mattn#283
usleep Implemented Closes mattn#285
FAQ Section Closes mattn#289
Compile Section closes mattn#295
FAQ Section Closes mattn#305
PR339 Closes mattn#318 mattn#321
Compilation Section Closes mattn#341
PR407 Closes mattn#364
Feature `sqlite_vtable` Closes mattn#393
Compile Section Closes mattn#416
sqlite_trace feature Closes mattn#433
Compilation Section Closes mattn#435
Compilation Section Closes mattn#443
Golang:1.6 Not Supported Closes mattn#445
Compilation Section Closes mattn#451
Compilation Section Closes mattn#467
Compilation Section Closes mattn#491
Compilation Section Closes mattn#495
Compilation Section Closes mattn#505
Compilation Section Closes mattn#557
Compilation Section Closes mattn#560
@mattn mattn closed this as completed in c9394b1 May 27, 2018
@JonRowe
Copy link

JonRowe commented Jul 23, 2018

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.

@gjrtimmer
Copy link
Collaborator

@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.

@utdrmac
Copy link

utdrmac commented Jul 24, 2018

@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.

@Peakchen
Copy link

Peakchen commented Jan 2, 2020

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.

here new problem is "i686-w64-mingw32-gcc: error: CreateProcess: No such file or directory", how to resolve?

@Allan-Nava
Copy link

I have this bug:


#17 29.00 # github.com/mattn/go-sqlite3
#17 29.00 sqlite3-binding.c:35901:42: error: 'pread64' undeclared here (not in a function); did you mean 'pread'?
#17 29.00 35901 |   { "pread64",      (sqlite3_syscall_ptr)pread64,    0  },
#17 29.00       |                                          ^~~~~~~
#17 29.00       |                                          pread
#17 29.00 sqlite3-binding.c:35919:42: error: 'pwrite64' undeclared here (not in a function); did you mean 'pwrite'?
#17 29.00 35919 |   { "pwrite64",     (sqlite3_syscall_ptr)pwrite64,   0  },
#17 29.00       |                                          ^~~~~~~~
#17 29.00       |                                          pwrite
#17 29.00 sqlite3-binding.c: In function 'seekAndRead':
#17 29.00 sqlite3-binding.c:35905:49: error: unknown type name 'off64_t'; did you mean 'off_t'?
#17 29.00 35905 | #define osPread64 ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent)
#17 29.00       |                                                 ^~~~~~~
#17 29.00 sqlite3-binding.c:38767:11: note: in expansion of macro 'osPread64'
#17 29.00 38767 |     got = osPread64(id->h, pBuf, cnt, offset);
#17 29.00       |           ^~~~~~~~~
#17 29.00 sqlite3-binding.c:35905:58: error: expected ')' before 'aSyscall'
#17 29.00 35905 | #define osPread64 ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent)
#17 29.00       |                   ~                                      ^~~~~~~~
#17 29.00 sqlite3-binding.c:38767:11: note: in expansion of macro 'osPread64'
#17 29.00 38767 |     got = osPread64(id->h, pBuf, cnt, offset);
#17 29.00       |           ^~~~~~~~~
#17 29.00 sqlite3-binding.c: In function 'seekAndWriteFd':
#17 29.00 sqlite3-binding.c:35923:57: error: unknown type name 'off64_t'; did you mean 'off_t'?
#17 29.00 35923 | #define osPwrite64  ((ssize_t(*)(int,const void*,size_t,off64_t))\
#17 29.00       |                                                         ^~~~~~~
#17 29.00 sqlite3-binding.c:38896:17: note: in expansion of macro 'osPwrite64'
#17 29.00 38896 |   do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
#17 29.00       |                 ^~~~~~~~~~
#17 29.00 sqlite3-binding.c:35924:21: error: expected ')' before 'aSyscall'
#17 29.00 35924 |                     aSyscall[13].pCurrent)
#17 29.00       |                     ^~~~~~~~
#17 29.00 sqlite3-binding.c:38896:17: note: in expansion of macro 'osPwrite64'
#17 29.00 38896 |   do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
#17 29.00       |                 ^~~~~~~~~~
#17 29.00 sqlite3-binding.c:[359](https://github.com/iesitalia/image-proxy/actions/runs/11372536680/job/31637080124#step:7:364)23:21: note: to match this '('
#17 29.00 35923 | #define osPwrite64  ((ssize_t(*)(int,const void*,size_t,off64_t))\
#17 29.00       |                     ^
#17 29.00 sqlite3-binding.c:38896:17: note: in expansion of macro 'osPwrite64'
#17 29.00 38896 |   do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
#17 29.00       |                 ^~~~~~~~~~
#17 ERROR: process "/bin/sh -c GO111MODULE=on CGO_ENABLED=1 GO_CFLAGS=\"-D_LARGEFILE64_SOURCE\" GOOS=linux GOARCH=amd64 go build -ldflags=\"-s -w\" -o imageproxy ./main.go" did not complete successfully: exit code: 1
------
 > [builder 7/7] RUN GO111MODULE=on CGO_ENABLED=1 GO_CFLAGS="-D_LARGEFILE64_SOURCE" GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o imageproxy ./main.go:
29.00       |                     ^~~~~~~~
29.00 sqlite3-binding.c:38896:17: note: in expansion of macro 'osPwrite64'
29.00 38896 |   do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
29.00       |                 ^~~~~~~~~~
29.00 sqlite3-binding.c:35923:21: note: to match this '('
29.00 35923 | #define osPwrite64  ((ssize_t(*)(int,const void*,size_t,off64_t))\
29.00       |                     ^
29.00 sqlite3-binding.c:38896:17: note: in expansion of macro 'osPwrite64'
29.00 38896 |   do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
29.00       |                 ^~~~~~~~~~
------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests