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

(Eloy Brodin) #1

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?

(Andrew Kroh) #2

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.

(Eloy Brodin) #3

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

go build no buildable Go source files in /usr/local/test/golang/src/

(Andrew Kroh) #4

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?

(Eloy Brodin) #5

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.

(Andrew Kroh) #6

With Packetbeat requiring CGO you probably need to set some additional environment variables. See

(Eloy Brodin) #7

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!

(system) #8

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