Compile packetbeat as 32 bits in a 64 bits environment (Linux)

How can I compile packetbeat in a 64 bits environment (linux) to generate a 32 bits executable?

I have tried "make crosscompile", which worked me on Winlogbeat. Then I read Build packetbeat on windows, so I downloaded beats-packer and tried to compile with "make packetbeat/deb".

Is this the right way? This project seems to clone again the repository, but I want to use mine.
How can I configure it?

On Linux with your Go build environment setup, does

$ go build

work for you from the packetbeat directory? This should build a 64-bit version. If that works then you can try running

$ GOARCH=386 go build

to try to build the 32-bit binary for linux.

When I try to compile it with that option I get the same error as compiling with crosscompile:

go build github.com/elastic/beats/vendor/github.com/tsg/gopacket/afpacket: no buildable Go source files in /usr/local/test/golang/src/github.com/elastic/beats/vendor/github.com/tsg/gopacket/afpacket

The only build tag I see on those files is // +build linux so that package should contain files when building on Linux. The regular 64-bit GOOS=linux GOARCH=amd64 go build command worked as expected?

Yes I have no problem compiling in 64 bits with Ubuntu 14.04. I have also tried to compile the same code with a Kubuntu 32 bits and it works too. But i'm not able to generate the 32 bit executable file from the 64 bits machine.

With Packetbeat requiring CGO you probably need to set some additional environment variables. See https://github.com/elastic/beats/blob/master/dev-tools/packer/docker/xgo-image/base/build.sh#L142-L143

I got it! Thanks for the information!
First, it's necessary to have installed libpcap 32 bits and then you must enable CGO

sudo dpkg --add-architecture i386
sudo apt-get update
apt-get install libpcap0.8-dev:i386

GOARCH=386 CGO_ENABLED=1 go build

I found this useful site:
Compiling go app that uses Cgo

Thank you!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.