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

Cross compile #26

Open
samsamm777 opened this issue Apr 5, 2018 · 12 comments
Open

Cross compile #26

samsamm777 opened this issue Apr 5, 2018 · 12 comments

Comments

@samsamm777
Copy link

samsamm777 commented Apr 5, 2018

Im having issues with cross compiling. Compiling normally on OSX works fine. However when i try the following it produces errors. Any ideas?

$ GOOS=linux go build
# github.com/discordapp/lilliput
../../discordapp/lilliput/lilliput.go:26: undefined: ImageHeader
../../discordapp/lilliput/lilliput.go:41: undefined: Framebuffer
../../discordapp/lilliput/lilliput.go:48: undefined: Framebuffer
../../discordapp/lilliput/ops.go:43: undefined: Framebuffer

Edit:
I get this error when building the deps for osx or linux.

checking for object file format of host system... Mach-O64
checking for object file format specifier (NAFLAGS) ... -fmacho64 -DMACHO -D__x86_64__
checking whether the assembler (nasm -fmacho64 -DMACHO -D__x86_64__) works... no
configure: error: installation or configuration problem: assembler cannot create object files.
@brian-armstrong-discord
Copy link
Contributor

Have you tried brew install nasm?

@samsamm777
Copy link
Author

@brian-armstrong-discord Yes I've now got all the deps installed. Initially thought that would fix it, however building with crosscompile still doesn't work.

@brian-armstrong-discord
Copy link
Contributor

What is the error?

@realtruckcgoltz
Copy link

I'd like to add my voice to this issue as well. It seems like cross-compiling, regardless of the host os, isn't working as hoped.

On macOS:

$ GOOS=linux go build
# github.com/discordapp/lilliput
../../go/src/github.com/discordapp/lilliput/lilliput.go:26:13: undefined: ImageHeader
../../go/src/github.com/discordapp/lilliput/lilliput.go:41:14: undefined: Framebuffer
../../go/src/github.com/discordapp/lilliput/lilliput.go:48:12: undefined: Framebuffer
../../go/src/github.com/discordapp/lilliput/ops.go:43:16: undefined: Framebuffer

On Linux:

$ GOOS=darwin go build
# github.com/discordapp/lilliput
../../go/src/github.com/discordapp/lilliput/lilliput.go:26:13: undefined: ImageHeader
../../go/src/github.com/discordapp/lilliput/lilliput.go:41:14: undefined: Framebuffer
../../go/src/github.com/discordapp/lilliput/lilliput.go:48:12: undefined: Framebuffer
../../go/src/github.com/discordapp/lilliput/ops.go:43:16: undefined: Framebuffer

go build in the same directory works regardless of platform.

My "go greeness" is showing here, but could it be that the platform is getting lost along the way, resulting in a build attempt that's just all kinds of confused?

@brian-armstrong-discord
Copy link
Contributor

Well, this package also has c deps that are needed, and compilation has to occur with cgo.

Maybe https://gist.github.com/steeve/6905542 is relevant?

@brian-armstrong-discord
Copy link
Contributor

It looks like if nothing else, in cross-compile mode, you need CGO_ENABLED=1. But you'll also need a valid cross-compile setup for compiling the C deps.

@RichardLindhout
Copy link
Contributor

Did you manage to work around this issue @samsamm777

@RichardLindhout
Copy link
Contributor

RichardLindhout commented Jun 6, 2020

docker run -it --rm \
  -v $GOPATH/src/github.com/MYPROJECT/app/backend:/go/src/github.com/MYPROJECT/app/backend \
  -w /go/src/github.com/MYPROJECT/app/backend \
  -e CGO_ENABLED=1 \
  docker.elastic.co/beats-dev/golang-crossbuild:1.14.4-main-debian8 \
  --build-cmd "go build" \
  -p "linux/amd64"

@RichardLindhout
Copy link
Contributor

Only this error left now:

/usr/bin/ld: cannot find -lpng
/usr/bin/ld: cannot find -lpng
collect2: error: ld returned 1 exit status
Error: failed building for linux/amd64: exit status 2
failed building for linux/amd64: exit status 2

@RichardLindhout
Copy link
Contributor

RichardLindhout commented Jun 6, 2020

docker run -it --rm \
  -v $GOPATH/src/github.com/MYPROJECT/app/backend:/go/src/github.com/MYPROJECT/app/backend \
  -w /go/src/github.com/MYPROJECT/app/backend \
  -e CGO_ENABLED=1 \
  docker.elastic.co/beats-dev/golang-crossbuild:1.14.4-main-debian8 \
  --build-cmd "
  apt-get update
   apt-get install gcc libc6-dev

 apt-get install libx11-dev xorg-dev libxtst-dev libpng++-dev   

 apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxkbcommon-dev

 apt-get install xsel xclip
  go build -v" \
  -p "linux/amd64"

Results in

/usr/bin/ld: /go/pkg/mod/github.com/discordapp/[email protected]/deps/linux/lib/libswscale.a(swscale.o): unrecognized relocation (0x2a) in section `.text'
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Error: failed building for linux/amd64: exit status 2
failed building for linux/amd64: exit status 2

@RichardLindhout
Copy link
Contributor

RichardLindhout commented Jun 6, 2020

Ah debian8 is old apparently crystal-lang/crystal#8653 (comment). It works with this command on OSX.


docker run -it --rm \
  -v $GOPATH/src/github.com/MYPROJECT/app/backend:/go/src/github.com/MYPROJECT/app/backend \
  -w /go/src/github.com/MYPROJECT/app/backend \
  -e CGO_ENABLED=1 \
  docker.elastic.co/beats-dev/golang-crossbuild:1.14.4-main \
  --build-cmd "
  apt-get -y update
   apt-get -y install gcc libc6-dev

 apt-get -y install libx11-dev xorg-dev libxtst-dev libpng++-dev   

 apt-get -y install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxkbcommon-dev
apt-get -y upgrade binutils
 apt-get -y install xsel xclip
  go build -v" \
  -p "linux/amd64"

@RichardLindhout
Copy link
Contributor

Final command :-D

It works 👍

docker run -it --rm \
  -v $GOPATH/src/github.com/MYPROJECT/app/backend:/go/src/github.com/MYPROJECT/app/backend \
  -w /go/src/github.com/MYPROJECT/app/backend \
  -e CGO_ENABLED=1 \
  docker.elastic.co/beats-dev/golang-crossbuild:1.14.4-main \
  --build-cmd "
apt-get -y update
apt-get -y install libpng++-dev   
go build -v
" \
  -p "linux/amd64"

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

4 participants