Caddy code doesn't compile on Windows

1. Caddy version (caddy version):

C:\WINDOWS\system32>caddy version
v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=

2. How I run Caddy:

I’m just in test mode, so nothing fancy. I start caddy from command line with :

caddy run

a. System environment:

WIndows 10 pro 64 Version 20H2, build 19042.685

b. Command:

caddy run

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:

localhost:2015 {

   respond "Hello, twirled! 2015"

localhost:2016 {

   respond "Hello, twirled! 2016"

3. The problem I’m having:

I am just getting started with go and caddy.
I am following the doc here: Extending Caddy — Caddy Documentation
to extend caddy
I created rons.go directly from what is shown on the quick-start:

package mymodule

import ""

func init() {

// Gizmo is an example; put your own type here.
type Gizmo struct {

// CaddyModule returns the Caddy module information.
func (Gizmo) CaddyModule() caddy.ModuleInfo {
	return caddy.ModuleInfo{
		ID:  "foo.gizmo",
		New: func() caddy.Module { return new(Gizmo) },

then run xcaddy list-modules:

C:\Users\Ron\Desktop\TGCS-Caligo\_SandBox>xcaddy list-modules
2021/01/11 14:02:11 [INFO] Temporary folder: C:\Users\Ron\AppData\Local\Temp\buildenv_2021-01-11-1402.231386619
2021/01/11 14:02:11 [INFO] Writing main module: C:\Users\Ron\AppData\Local\Temp\buildenv_2021-01-11-1402.231386619\main.go
2021/01/11 14:02:11 [INFO] Initializing Go module
2021/01/11 14:02:11 [INFO] exec (timeout=10s): C:\Go\bin\go.exe mod init caddy
go: creating new go.mod: module caddy
2021/01/11 14:02:11 [INFO] Replace rons => C:\Users\Ron\Desktop\TGCS-Caligo\_SandBox
2021/01/11 14:02:12 [INFO] exec (timeout=10s): C:\Go\bin\go.exe mod edit -replace rons=C:\Users\Ron\Desktop\TGCS-Caligo\_SandBox
2021/01/11 14:02:12 [INFO] Pinning versions
2021/01/11 14:02:12 [INFO] exec (timeout=0s): C:\Go\bin\go.exe get -d -v
go: upgrade => v2.3.0
2021/01/11 14:02:13 [INFO] Build environment ready
2021/01/11 14:02:13 [INFO] Building Caddy
2021/01/11 14:02:13 [INFO] exec (timeout=0s): C:\Go\bin\go.exe build -o C:\Users\Ron\Desktop\TGCS-Caligo\_SandBox\caddy.exe -ldflags -w -s -trimpath
# caddy
c:\go\src\caddy\caddy.go:62:11: undefined: AdminConfig
c:\go\src\caddy\caddy.go:63:11: undefined: Logging
c:\go\src\caddy\caddy.go:75:10: undefined: ModuleMap
c:\go\src\caddy\caddy.go:102:43: undefined: rawConfigKey
c:\go\src\caddy\caddy.go:124:9: undefined: unsyncedConfigAccess
c:\go\src\caddy\caddy.go:130:37: undefined: rawConfigKey
c:\go\src\caddy\caddy.go:132:10: undefined: APIError
c:\go\src\caddy\caddy.go:140:3: undefined: Log
c:\go\src\caddy\caddy.go:146:34: undefined: rawConfigKey
c:\go\src\caddy\caddy.go:588:3: undefined: rawConfigKey
c:\go\src\caddy\caddy.go:146:34: too many errors
2021/01/11 14:02:14 [INFO] Cleaning up temporary folder: C:\Users\Ron\AppData\Local\Temp\buildenv_2021-01-11-1402.231386619
2021/01/11 14:02:14 [ERROR] exit status 2

4. Error messages and/or full log output:

as shown above

5. What I already tried:

I completely uninstalled go, caddy, xcaddy and reinstalled - no difference.
I modified the sample module from the webpage to change gizmo to gizmo1, and mymodule to ronsmodule - no difference.
I attempted to build caddy from source with “go buyile”, but it wants gcc, which (on windows) wants cygwin or mingW, so I installed the binary - it runs
xcaddy appears to want modules that aren’t here or not where it expects to find them.

6. Links to relevant resources:

Huh… I’ve never seen that before. (I don’t use Windows though, either.)

Is the working copy of the Caddy source perfectly clean?

Does your own code compile (go build)?

Hi Matt,
I haven’t made any changes to the sourcve. I tried go build to build caddy, but it barks about wanting gcc executables, and gcc wants cygwin or mingw, so I didn’t go any further down that path.

I haven’t built any code of my own with go.

Hmm, what about this part of the guide:

In a new Go module

Did you run this in a Go module? (go mod init)

If you’re an absolute Go beginner, you’ll want to start with this: How to Write Go Code - The Go Programming Language

Yes, I ran “go mod init rons.go”. and it created the go.mod file.
I did go thru the go tutorial too.

I honestly don’t know then. You’ll probably have to fiddle with it.

It’s not an xcaddy problem – xcaddy doesn’t yield those errors, those are from the Go compiler – so I would navigate into the caddy source directory and run go build and see where it fails, then investigate in those files and see why.

Thanks Matt. I’m installing mingw and gcc now, so I should be able to go build.

1 Like

I recommend using to install things on windows. You can use it to set yourself up with a go environment pretty easily.

I’ve never heard of scoop, but I’ll take a look. Thanks!

Hi Matt, I installed MingW & GCC, following the doc at: Build from source — Caddy Documentation
now the “go build” starts, but fails with invalid parms for ld.exe.

C:\caddy\cmd\caddy>go build
c:\go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
c:/mingw/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: unrecognized option '--high-entropy-va'
c:/mingw/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: use the --help option for usage information
collect2.exe: error: ld returned 1 exit status

running help for ld, there is no parm that includes “high” or “entropy”.

Any clues?

Also, looking at caddy.go, it does reference "adminConsole, Logging, etc as shown in the error messages from xcaddy. How are these supposed to be resolved?

I have no idea… honestly I’ve never seen these errors before nor do I use Windows or have experience there. Your best bet would be to ask the Go community:

I’ve only ever had problems using mingw (at least directly).

I still recommend using scoop.

scoop install go gcc

See the package definitions for those to see what it does:

xcaddy works just fine for me on windows that way.

AFAIK I didn’t even need gcc myself for things to compile. Caddy is a pure-go project, so you shouldn’t need it I think. You might need to set CGO_ENABLED=0 in your system environment for it to stop trying to use gcc. But I don’t think I needed to do that :thinking:

1 Like

Thanks! I installed scoop, and started the “scoop install go gcc” failed at third entry.
I checked the repo, expat has been updated to 2.2.10, but the install doesn’t appear to know it.
Do I download a local copy of the json and fix it on my PC?

PS C:\Users\Ron> scoop install go gcc
Installing '7zip' (19.00) [64bit]
7z1900-x64.msi (1.7 MB) [=====================================================================================] 100%
Checking hash of 7z1900-x64.msi ... ok.
Extracting 7z1900-x64.msi ... done.
Linking ~\scoop\apps\7zip\current => ~\scoop\apps\7zip\19.00
Creating shim for '7z'.
Creating shortcut for 7-Zip (7zFM.exe)
'7zip' (19.00) was installed successfully!
Installing 'gcc' (9.3.0-2) [64bit]
mingw-w64-x86_64-binutils-2.34-1-any.pkg.tar.xz (13.9 MB) [===================================================] 100%
Checking hash of mingw-w64-x86_64-binutils-2.34-1-any.pkg.tar.xz ... ok.
mingw-w64-x86_64-crt-git- (3.1 MB) [======================================] 100%
Checking hash of mingw-w64-x86_64-crt-git- ... ok.
The remote server returned an error: (404) Not Found.
URL is not valid
PS C:\Users\Ron>

Nevermind! I’m abandoning Caddy. I never expected to have to rebuild the whole thing to extend it, but ok.
I shouldn’t have to debug the freakin’ build routines, before I even start MY work! Caddy obviously isn’t ready for prime time - good luck with it.

That’s core to Caddy’s architecture:

It’s not our fault that you’re having trouble using your computer. The issues you’re having have nothing to do with Caddy, and everything to do with the way you configured your environment.

If it makes you feel good to blame me that gcc won’t build your code following 2 different methods of yours, then go ahead. Telling the user to “fiddle with it” doesn’t help. Gcc works, golang works, mingw works, Still can’t build caddy. This was an experiment to try the new kid on the block.

Now I’m going to use a more mature server.

As I said before good luck with it.