# Build telegraf in windows fails

**URL:** https://community.influxdata.com/t/build-telegraf-in-windows-fails/25988
**Category:** Telegraf
**Tags:** windows
**Created:** [August 3, 2022, 12:31pm UTC](https://community.influxdata.com/t/build-telegraf-in-windows-fails/25988 "2022-08-03T12:31:53Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![barts2108](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/barts2108/32/10674_2.png) [@barts2108](https://community.influxdata.com/u/barts2108)
#### Post date: [August 3, 2022, 12:31pm UTC](https://community.influxdata.com/t/build-telegraf-in-windows-fails/25988/1 "2022-08-03T12:31:53Z")

</div>

In a clean windows 10, Installed

- Git-2.37.1-64-bit
- go1.19.windows-amd64

then executed the following to install GNU.

- Winget install GnuWin32.make

- Added path to make.exe in the system environment PATH.

Executed (as per readme [https://github.com/influxdata/telegraf#build-from-source](https://github.com/influxdata/telegraf#build-from-source) )

```
git -c http.sslVerify=false clone https://github.com/influxdata/telegraf.git
cd telegraf
make

```

Then the info starts as this:

```
go mod download -x
# get https://proxy.golang.org/cloud.google.com/go/bigquery/@v/v1.33.0.mod
# get https://proxy.golang.org/cloud.google.com/go/@v/v0.102.1.mod
# get https://proxy.golang.org/cloud.google.com/go/@v/v0.102.1.mod: 200 OK (0.152s)

```

until 7488 lines later it fails with this

```
# get https://proxy.golang.org/sigs.k8s.io/yaml/@v/v1.2.0.zip
# get https://proxy.golang.org/sigs.k8s.io/yaml/@v/v1.2.0.zip: 200 OK (0.148s)
env -u GOOS -u GOARCH -u GOARM -- go build -o ./tools/license_checker/license_checker ./tools/license_checker
process_begin: CreateProcess(NULL, env -u GOOS -u GOARCH -u GOARM -- go build -o ./tools/license_checker/license_checker ./tools/license_checker, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [build_tools] Error 2

```

Probably I am doing something wrong, but can’t find out what.  
I want to build telegraf on windows 10 for windows

---

<div class="post-metadata">

### Author: ![jpowers](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jpowers/32/8569_2.png) [@jpowers](https://community.influxdata.com/u/jpowers)
#### Post date: [August 3, 2022, 1:58pm UTC](https://community.influxdata.com/t/build-telegraf-in-windows-fails/25988/2 "2022-08-03T13:58:08Z")

</div>

Hi!

> [@barts2108](#):
>
> ```auto
> env -u GOOS -u GOARCH -u GOARM -- go build -o ./tools/license_checker/license_checker ./tools/license_checker
> process_begin: CreateProcess(NULL, env -u GOOS -u GOARCH -u GOARM -- go build -o ./tools/license_checker/license_checker ./tools/license_checker, ...) failed.
> make (e=2): The system cannot find the file specified.
> make: *** [build_tools] Error 2
> 
> ```

We don’t get a lot of folks building on Windows, but you are right it does look like the Makefile is currently broken in those environments. I have filed [make: fails on Windows environments · Issue #11609 · influxdata/telegraf · GitHub](https://github.com/influxdata/telegraf/issues/11609) to track this and to get a fix for you.

For now, you can manually run:

```auto
go build .\cmd\telegraf\

```

Which will pass a lot of the checks and other things that run during a build and get yourself a binary.

---

<div class="post-metadata">

### Author: ![barts2108](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/barts2108/32/10674_2.png) [@barts2108](https://community.influxdata.com/u/barts2108)
#### Post date: [August 3, 2022, 2:27pm UTC](https://community.influxdata.com/t/build-telegraf-in-windows-fails/25988/3 "2022-08-03T14:27:27Z")

</div>

> [@jpowers](#):
>
> We don’t get a lot of folks building on Windows

The manual build runs and creates a 200MB executable. I guess that’s because of all plugins, but its not relevant for my case. I have subscribed to the github issue #11609 .

---

<div class="post-metadata">

### Author: ![jpowers](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jpowers/32/8569_2.png) [@jpowers](https://community.influxdata.com/u/jpowers)
#### Post date: [August 3, 2022, 2:45pm UTC](https://community.influxdata.com/t/build-telegraf-in-windows-fails/25988/4 "2022-08-03T14:45:34Z")

</div>

> [@barts2108](#):
>
> The manual build runs and creates a 200MB executable.

Correct, by default, we build with all plugins included.

We are [working on a tool](https://github.com/influxdata/telegraf/pull/11524) to allow users to build a smaller telegraf with only the plugins that they currently require.

---

<div class="post-metadata">

### Author: ![barts2108](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/barts2108/32/10674_2.png) [@barts2108](https://community.influxdata.com/u/barts2108)
#### Post date: [August 3, 2022, 5:37pm UTC](https://community.influxdata.com/t/build-telegraf-in-windows-fails/25988/5 "2022-08-03T17:37:15Z")

</div>

I have seen a lot of reactions in github while I was biking back home… About MingW and other things… My setup does not have MingW (yet). If I modify the makefile in this way : (removed the env command from HOSTGO as I do not know how to change it for windows … probably a set command or so)

```
GOARCH ?= $(shell go env GOARCH)
#HOSTGO := env -u GOOS -u GOARCH -u GOARM -- go
HOSTGO := go
ifeq ($(GOOS), windows)
    EXEEXT := .exe
endif

```

and add the EXEEXT to the tools to be built

```
build_tools:
$(HOSTGO) build -o ./tools/license_checker/license_checker$(EXEEXT) ./tools/license_checker
$(HOSTGO) build -o ./tools/readme_config_includer/generator$(EXEEXT) ./tools/readme_config_includer/generator.go

```

It seems to be able to build from a simple CMD.exe window.

Unfortunately I am new user and not allowed to upload my makefile. I will do another test from scratch from the git clone until compiling

---

<div class="post-metadata">

### Author: ![barts2108](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/barts2108/32/10674_2.png) [@barts2108](https://community.influxdata.com/u/barts2108)
#### Post date: [August 3, 2022, 5:57pm UTC](https://community.influxdata.com/t/build-telegraf-in-windows-fails/25988/6 "2022-08-03T17:57:41Z")

</div>

Second test to build all from a cmd.exe succeeds too.

@jpowers : Can you help check how this fits in “building on Windows for linux” and “building on linux for windows” etc ?

---

<div class="post-metadata">

### Author: ![jpowers](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jpowers/32/8569_2.png) [@jpowers](https://community.influxdata.com/u/jpowers)
#### Post date: [August 3, 2022, 6:43pm UTC](https://community.influxdata.com/t/build-telegraf-in-windows-fails/25988/7 "2022-08-03T18:43:27Z")

</div>

> Unfortunately I am new user and not allowed to upload my makefile. I will do another test from scratch from the git clone until compiling

Hey! I appreciate you trying to make it work.

> ```auto
> #HOSTGO := env -u GOOS -u GOARCH -u GOARM -- go
> HOSTGO := go
> 
> ```

Unfortunately, this will re-introduce the cross-build issue. It does seem that users are running with powershell, as we got another issue today. We can continue in that issue and see where we get.

Thanks again!

---

<div class="post-metadata">

### Author: ![barts2108](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/barts2108/32/10674_2.png) [@barts2108](https://community.influxdata.com/u/barts2108)
#### Post date: [August 4, 2022, 6:12am UTC](https://community.influxdata.com/t/build-telegraf-in-windows-fails/25988/8 "2022-08-04T06:12:59Z")

</div>

How about redefining HOSTGO in the if (windows) ?  
EDIT: nevermind, I see the changes have been checked in already. I will see if I can start from scratch once more and if I can get everything compiling. If not, I might be coming back here with a question.

---

<div class="post-metadata">

### Author: ![barts2108](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/barts2108/32/10674_2.png) [@barts2108](https://community.influxdata.com/u/barts2108)
#### Post date: [August 4, 2022, 10:55am UTC](https://community.influxdata.com/t/build-telegraf-in-windows-fails/25988/9 "2022-08-04T10:55:54Z")

</div>

Back here for a last update:

Using git-bash works, and now is able to build the executables for windows and linux on windows.

For those looking for the information how to use it, I managed to get it working with these steps

1. Start cmd.exe

2. set environment variable(s) GOOS, GOARCH, GOARM as required. If they are not set, it seems that the compilation by default is for the platform and architecture you’re running on. After setting the environment variables continue at next point

3. Start git-bash

4. cd to the folder you want to use for your build

5. `git clone https://github.com/influxdata/telegraf.git`

6. cd to the `telegraf` folder

7. `make`

---

<div class="post-metadata">

### Author: ![jpowers](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jpowers/32/8569_2.png) [@jpowers](https://community.influxdata.com/u/jpowers)
#### Post date: [August 4, 2022, 1:29pm UTC](https://community.influxdata.com/t/build-telegraf-in-windows-fails/25988/10 "2022-08-04T13:29:15Z")

</div>

Thanks for this!

Should you need to change those Go variables, You should also be able to set on the command line in the git-bash shell. For example, if I wanted to cross-build for the arm64 architecture:

```auto
GOARCH=arm64 make

```
