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

**URL:** https://discuss.elastic.co/t/compile-packetbeat-as-32-bits-in-a-64-bits-environment-linux/69174
**Category:** Beats
**Tags:** packetbeat
**Created:** [December 15, 2016, 2:35pm UTC](https://discuss.elastic.co/t/compile-packetbeat-as-32-bits-in-a-64-bits-environment-linux/69174 "2016-12-15T14:35:53Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![PinXo](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@PinXo](https://discuss.elastic.co/u/PinXo)
#### Post date: [December 15, 2016, 2:35pm UTC](https://discuss.elastic.co/t/compile-packetbeat-as-32-bits-in-a-64-bits-environment-linux/69174/1 "2016-12-15T14:35:53Z")

</div>

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](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/7), 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?

---

<div class="post-metadata">

### Author: ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)
#### Post date: [December 16, 2016, 6:18pm UTC](https://discuss.elastic.co/t/compile-packetbeat-as-32-bits-in-a-64-bits-environment-linux/69174/2 "2016-12-16T18:18:58Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![PinXo](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@PinXo](https://discuss.elastic.co/u/PinXo)
#### Post date: [December 19, 2016, 7:40am UTC](https://discuss.elastic.co/t/compile-packetbeat-as-32-bits-in-a-64-bits-environment-linux/69174/3 "2016-12-19T07:40:33Z")

</div>

> [@andrewkroh](#):
>
> GOARCH=386 go build

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:](http://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

---

<div class="post-metadata">

### Author: ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)
#### Post date: [December 19, 2016, 2:11pm UTC](https://discuss.elastic.co/t/compile-packetbeat-as-32-bits-in-a-64-bits-environment-linux/69174/4 "2016-12-19T14:11:21Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![PinXo](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@PinXo](https://discuss.elastic.co/u/PinXo)
#### Post date: [December 19, 2016, 2:23pm UTC](https://discuss.elastic.co/t/compile-packetbeat-as-32-bits-in-a-64-bits-environment-linux/69174/5 "2016-12-19T14:23:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)
#### Post date: [December 19, 2016, 5:16pm UTC](https://discuss.elastic.co/t/compile-packetbeat-as-32-bits-in-a-64-bits-environment-linux/69174/6 "2016-12-19T17:16:40Z")

</div>

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](https://github.com/elastic/beats/blob/master/dev-tools/packer/docker/xgo-image/base/build.sh#L142-L143)

---

<div class="post-metadata">

### Author: ![PinXo](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@PinXo](https://discuss.elastic.co/u/PinXo)
#### Post date: [December 20, 2016, 8:02am UTC](https://discuss.elastic.co/t/compile-packetbeat-as-32-bits-in-a-64-bits-environment-linux/69174/7 "2016-12-20T08:02:57Z")

</div>

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](http://dequeue.blogspot.com.es/2015/09/compiling-go-app-that-uses-cgo-to-run.html)

Thank you!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [January 17, 2017, 8:02am UTC](https://discuss.elastic.co/t/compile-packetbeat-as-32-bits-in-a-64-bits-environment-linux/69174/8 "2017-01-17T08:02:57Z")

</div>

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