# \[SOLVED\] Build packetbeat on windows

**URL:** https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161
**Category:** Beats
**Tags:** packetbeat
**Created:** [November 20, 2015, 2:28pm UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161 "2015-11-20T14:28:41Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![bering](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bering/32/4044_2.png) [@bering](https://discuss.elastic.co/u/bering)
#### Post date: [November 20, 2015, 2:28pm UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/1 "2015-11-20T14:28:41Z")

</div>

I am trying to build packetbeat on a windows 10 computer, steps so far:

install:  
Go 1.5.1  
Git 2.6.3  
bzr 2.5.1  
gopath=c:\go\bin  
goroot=c:\go\

created a directory structure c:\go\src\[github.com](http://github.com)\elastic  
cd c:\go\src\[github.com](http://github.com)\elastic  
git clone [https://github.com/elastic/packetbeat.git](https://github.com/elastic/packetbeat.git)  
cd packetbeat

go install  
then i get this error:

# [github.com/elastic/packetbeat/protos/thrift](http://github.com/elastic/packetbeat/protos/thrift)

protos\thrift\thrift\_idl.go:30: field.Id undefined (type \*parser.Field has no field or method Id, but does have ID)  
protos\thrift\thrift\_idl.go:31: field.Id undefined (type \*parser.Field has no field or method Id, but does have ID)  
protos\thrift\thrift\_idl.go:39: field.Id undefined (type \*parser.Field has no field or method Id, but does have ID)

# [github.com/tsg/gopacket/pcap](http://github.com/tsg/gopacket/pcap)

exec: "gcc": executable file not found in %PATH%

Does anyone know how to fix this?

Cheers

---

<div class="post-metadata">

### Author: ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)
#### Post date: [November 20, 2015, 2:32pm UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/2 "2015-11-20T14:32:23Z")

</div>

packetbeat is using godep for vendoring. The thrift library on your system is newer then the one used by packetbeat. In order to build packetbeat go to $GOPATH/src/github.com/elastic/packetbeat and type 'make'. This gets you the executable packetbeat in said directory.

---

<div class="post-metadata">

### Author: ![tudor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tudor/32/3753_2.png) [@tudor](https://discuss.elastic.co/u/tudor)
#### Post date: [November 21, 2015, 5:56pm UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/3 "2015-11-21T17:56:27Z")

</div>

I think you are hitting two issues: one is that you don't compile against the deps from Godep, like Steffen is saying, and the other is that you need a C compiler for the Cgo parts.

For the Godep part, if you don't want/can't use the Makefile, you can setup a custom GOPATH, that includes the `Godeps/_worspace` folder, e.g. `GOPATH=c:\go;c:\go\src\github.com\elastic\packetbeat`. Then you can use `go build` normally.

For the C compiler part, I recommend installing `mingw`, if you have chocolatey, it's as easy as `choco.exe install mingw`

Also, any reason for compiling it yourself? We do provide windows binaries.

---

<div class="post-metadata">

### Author: ![bering](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bering/32/4044_2.png) [@bering](https://discuss.elastic.co/u/bering)
#### Post date: [November 24, 2015, 12:35pm UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/4 "2015-11-24T12:35:24Z")

</div>

I am really new to Go, and I can't figure out why make does not work:  
C:\Go\src\[github.com](http://github.com)\elastic\packetbeat\>make  
Must run make.bat from Go src directory.

Running make from the c:\src gives this:  
C:\Go\src\>make [github.com/elastic/packetbeat](http://github.com/elastic/packetbeat)

##### Building Go bootstrap tool.

cmd/dist  
ERROR: Cannot find C:\Users\admin\Go1.4\bin\go.exe  
"Set GOROOT\_BOOTSTRAP to a working Go tree \>= Go 1.4."

And when I try and add the GOROOT\_BOOTSTRAP variable my Go starts giving me compile not found errors and I have to reinstall Go to make it work again.

So I followed Tudor's advice and modified my GOPATH

My paths:  
GOPATH=c:\go;c:\go\src\[github.com](http://github.com)\elastic\packetbeat  
GOROOT=c:\go\

That gives me the following error (there is no header file for pcap.h on my system)

C:\Go\src\[github.com](http://github.com)\elastic\packetbeat\>go build

# [github.com/elastic/packetbeat/protos/thrift](http://github.com/elastic/packetbeat/protos/thrift)

protos\thrift\thrift\_idl.go:30: field.Id undefined (type \*parser.Field has no field or method Id, but does have ID)  
protos\thrift\thrift\_idl.go:31: field.Id undefined (type \*parser.Field has no field or method Id, but does have ID)  
protos\thrift\thrift\_idl.go:39: field.Id undefined (type \*parser.Field has no field or method Id, but does have ID)

# [github.com/tsg/gopacket/pcap](http://github.com/tsg/gopacket/pcap)

....\tsg\gopacket\pcap\pcap.go:18:18: fatal error: pcap.h: No such file or directory  
#include \<pcap.h\>  
^  
compilation terminated.

The reason why I want to compile myself is that I will try and add support for at second windows driver "Microsoft Network Monitor 3 Driver" so I don't have to install the Riverbed driver, hope that it makes sense 🙂

---

<div class="post-metadata">

### Author: ![bering](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bering/32/4044_2.png) [@bering](https://discuss.elastic.co/u/bering)
#### Post date: [November 25, 2015, 1:44pm UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/5 "2015-11-25T13:44:40Z")

</div>

I just tried to compile packetbeat on my mac and it just works, can I compile the windows binary from my mac? Or how do you manage to compile the windows binaries?

---

<div class="post-metadata">

### Author: ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)
#### Post date: [November 26, 2015, 9:24am UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/6 "2015-11-26T09:24:26Z")

</div>

UPDATE: For packetbeat it is not as easy as described below because of cgo. The easy option is to just download the nightly build in case you want to run the most recent version: [https://beats-nightlies.s3.amazonaws.com/index.html?prefix=packetbeat/](https://beats-nightlies.s3.amazonaws.com/index.html?prefix=packetbeat/) Otherwise have a look at [https://github.com/elastic/beats-packer](https://github.com/elastic/beats-packer) where we do the builds ourself. `make xgo-image && make packetbeat` should to the build.

@bering Yes, you can create the windows binary on your Mac. Use `make crosscompile` for this. It will run the scripts/crosscompile.sh script and built it for all available platforms.

---

<div class="post-metadata">

### Author: ![bering](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bering/32/4044_2.png) [@bering](https://discuss.elastic.co/u/bering)
#### Post date: [December 8, 2015, 10:12pm UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/7 "2015-12-08T22:12:50Z")

</div>

I have just tried to build packetbeat again from my mac, I cloned the new beats with git clone [https://github.com/elastic/beats](https://github.com/elastic/beats)  
From src/github.com/elastic/beats/packetbeat I can run `make` without any errors but running `make crosscompile` for darwin and windows gives me this error:

```
go get github.com/mitchellh/gox
mkdir -p build/bin
gox -output="build/bin/{{.Dir}}-{{.OS}}-{{.Arch}}" -os="darwin windows" 
Number of parallel builds: 7

--> windows/amd64: github.com/elastic/beats/packetbeat
--> darwin/amd64: github.com/elastic/beats/packetbeat
--> windows/386: github.com/elastic/beats/packetbeat
--> darwin/386: github.com/elastic/beats/packetbeat

4 errors occurred:
--> darwin/amd64 error: exit status 2
Stderr: # github.com/elastic/beats/packetbeat/sniffer
sniffer/sniffer.go:26: undefined: pcap.Handle
sniffer/sniffer.go:31: undefined: pcap.Dumper

--> windows/amd64 error: exit status 2
Stderr: # github.com/elastic/beats/packetbeat/sniffer
sniffer/sniffer.go:26: undefined: pcap.Handle
sniffer/sniffer.go:31: undefined: pcap.Dumper

--> darwin/386 error: exit status 2
Stderr: # github.com/elastic/beats/packetbeat/sniffer
sniffer/sniffer.go:26: undefined: pcap.Handle
sniffer/sniffer.go:31: undefined: pcap.Dumper

--> windows/386 error: exit status 2
Stderr: # github.com/elastic/beats/packetbeat/sniffer
sniffer/sniffer.go:26: undefined: pcap.Handle
sniffer/sniffer.go:31: undefined: pcap.Dumper

make: *** [crosscompile] Error 1

```

Can anyone see what I am missing and how the get past this message?

---

<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 9, 2015, 3:11am UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/8 "2015-12-09T03:11:09Z")

</div>

We do not use `make crosscompile` to build Packetbeat because Packetbeat uses cgo, a golang command that enables go code to depend on C code. Because of this dependency you must have a C compiler for Windows, the required header files, and libraries in order to build.

Like @ruflin said, we use [beats-packer](https://github.com/elastic/beats-packer) to build for Windows. The beats-packer project has a docker container with a C cross-compiler and the required pcap libraries for Windows. [Here's](https://github.com/elastic/beats-packer/blob/master/docker/xgo-image/base/build.sh#L102) the command that does the build in the container. To use beats-packer you would just need to have docker setup and then run `make xgo-image && make packetbeat`.

To build Packetbeat on Windows you would need to have golang setup, install mingw, install winpcap developer pack to [C:/WpdPack/Lib](https://github.com/elastic/beats/blob/master/vendor/github.com/tsg/gopacket/pcap/pcap.go#L15). Our [Vagrant box](https://github.com/elastic/beats/blob/master/Vagrantfile) in elastic/beats has all of this setup except for the winpcap developer pack (been meaning to fix this).

---

<div class="post-metadata">

### Author: ![bering](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bering/32/4044_2.png) [@bering](https://discuss.elastic.co/u/bering)
#### Post date: [December 10, 2015, 1:41pm UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/9 "2015-12-10T13:41:04Z")

</div>

I downloaded the win2012 vigrant box and was able to build packetbeat on it by adding WpdPack 4.1.2 to c:\wpdpack\lib

I compared the setup from the vigrant box to my windows 10 setup and noticed that there was an additional environment variable set:  
`GO15VENDOREXPERIMENT=1`  
With this variable set I am able to build packetbeat on my windows 10 🙂 this enables go to use the go files from the vendor directory.

---

<div class="post-metadata">

### Author: ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)
#### Post date: [December 10, 2015, 4:43pm UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/10 "2015-12-10T16:43:31Z")

</div>

Yeah, over the time of this post we switched from godep go using vendor go experiment. Glad to hear it works now.

---

<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 11, 2015, 2:51pm UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/11 "2015-12-11T14:51:10Z")

</div>

@bering FYI: The Vagrant box has been updated to include the WinPcap developer pack.

> <https://github.com/elastic/beats/pull/500>

---

<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: [July 5, 2017, 9:57pm UTC](https://discuss.elastic.co/t/solved-build-packetbeat-on-windows/35161/12 "2017-07-05T21:57:33Z")

</div>


