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

cannot cross-compile arm binary on x86 platform #1787

Open
zync-mzy opened this issue Apr 22, 2018 · 4 comments
Open

cannot cross-compile arm binary on x86 platform #1787

zync-mzy opened this issue Apr 22, 2018 · 4 comments

Comments

@zync-mzy
Copy link

$ GOARCH=arm GOOS=linux make BUILDTAGS="" EXTRA_LDFLAGS="-extldflags '-static'" 
go build -buildmode=pie  -ldflags "-X main.gitCommit="1f11dc5dba5213400482cd974db20ee1408d2c7f" -X main.version=1.0.0-rc5+dev -extldflags '-static'" -tags "" -o runc .
go build github.com/opencontainers/runc/libcontainer/nsenter: no buildable Go source files in /home/zync/Code/go/src/github.com/opencontainers/runc/libcontainer/nsenter
Makefile:32: recipe for target 'runc' failed
make: *** [runc] Error 1

Could any body tell me how to make it? Any suggestions would be appreciated!

@bzub
Copy link

bzub commented Nov 24, 2018

Cross compiling with cgo in the mix (nsenter package) is a bit more involved. See golang/go#24433

Hopefully the cgo bits will be turned into pure Go at one point, though: #1795

@bzub
Copy link

bzub commented Nov 24, 2018

You will need to set up a cross compile toolchain, I'm not knowledgeable enough to recommend precise steps. I can tell you with confidence that you at least need to specify CGO_ENABLED=1 since the go tool tries to disable cgo when cross compiling, which is why you get that particular error message.

@zync-mzy
Copy link
Author

zync-mzy commented Nov 29, 2018

@bzub Thanks a lot for your reply! Since I know what the problem is now, I will try again to figure it out.

@bzub
Copy link

bzub commented Dec 2, 2018

I got it working without being completely statically linked. Add CC=arm-linux-gnueabihf-gcc or whatever cross compiler you can install for your system. Also add build_static to the BUILDTAGS= which disables systemd support.

For example on Arch Linux compiling for arm64 (raspberry pi 3) I was successful with installing the aarch64-linux-gnu-gcc package and using CC=aarch64-linux-gnu-gcc

Now getting it to work with seccomp is what I haven't accomplished. There's actually a make target for static building to reference. I have gotten this far:

$ make static GOARCH="arm64" CGO_ENABLED=1 CC="aarch64-linux-gnu-gcc" CGO_CFLAGS="-I/usr/aarch64-linux-gnu/include/linux -g -O2"
CGO_ENABLED=1 go build  -tags "seccomp netgo osusergo static_build" -installsuffix netgo -ldflags "-w -extldflags -static -X main.gitCommit="4932620b62
37ed2a91aa5b5ca8cca6a73c10311b" -X main.version=1.0.0-rc6+dev " -o runc .
# runtime/cgo
In file included from _cgo_export.c:3:
/usr/aarch64-linux-gnu/usr/include/stdlib.h:97:8: error: unknown type name 'size_t'
 extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
        ^~~~~~

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

2 participants