Build telegraf in windows fails

In a clean windows 10, Installed

  • Git-2.37.1-64-bit

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 )

git -c http.sslVerify=false clone
cd telegraf

Then the info starts as this:

go mod download -x
# get
# get
# get 200 OK (0.152s)

until 7488 lines later it fails with this

# get
# get 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


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 to track this and to get a fix for you.

For now, you can manually run:

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.

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 .

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

We are working on a tool to allow users to build a smaller telegraf with only the plugins that they currently require.

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

and add the EXEEXT to the tools to be built

$(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

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 ?

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.

#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!

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.

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

    "C:\Program Files\Git\git-bash.exe" --cd-to-home

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

  5. git clone

  6. cd to the telegraf folder

  7. make

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:

GOARCH=arm64 make