Bulding from source fails at cgo: exec /missing-cc: fork/exec /missing-cc: no such file or directory

I’m failing to build Caddy from source.

go version go1.15.7 linux/amd64

Command/output:

git clone https://github.com/caddyserver/caddy.git
...
...

~/.../cmd/caddy# go build
go: downloading golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
go: downloading go.uber.org/zap v1.16.0
go: downloading github.com/prometheus/client_golang v1.9.0
go: downloading github.com/smallstep/certificates v0.15.4
go: downloading github.com/smallstep/cli v0.15.2
go: downloading github.com/caddyserver/certmagic v0.12.1-0.20210126230115-267fdad76a0f
go: downloading github.com/smallstep/truststore v0.9.6
go: downloading github.com/go-chi/chi v4.1.2+incompatible
go: downloading github.com/yuin/goldmark v1.2.1
go: downloading go.uber.org/multierr v1.5.0
go: downloading github.com/mholt/acmez v0.1.3
go: downloading github.com/alecthomas/chroma v0.8.2
go: downloading github.com/prometheus/common v0.15.0
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/google/cel-go v0.6.0
go: downloading github.com/klauspost/cpuid v1.2.5
go: downloading go.uber.org/atomic v1.6.0
go: downloading github.com/prometheus/client_model v0.2.0
go: downloading github.com/Masterminds/sprig/v3 v3.1.0
go: downloading github.com/klauspost/cpuid/v2 v2.0.1
go: downloading github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac
go: downloading github.com/golang/protobuf v1.4.3
go: downloading google.golang.org/protobuf v1.24.0
go: downloading github.com/prometheus/procfs v0.2.0
go: downloading github.com/naoina/toml v0.1.1
go: downloading golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
go: downloading github.com/libdns/libdns v0.1.0
go: downloading github.com/klauspost/compress v1.11.3
go: downloading github.com/spf13/cast v1.3.1
go: downloading github.com/cespare/xxhash v1.1.0
go: downloading github.com/cespare/xxhash/v2 v2.1.1
go: downloading github.com/urfave/cli v1.22.2
go: downloading github.com/imdario/mergo v0.3.8
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/dlclark/regexp2 v1.2.0
go: downloading github.com/mitchellh/copystructure v1.0.0
go: downloading github.com/miekg/dns v1.1.30
go: downloading github.com/naoina/go-stringutil v0.1.0
go: downloading github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691
go: downloading github.com/google/uuid v1.1.1
go: downloading github.com/mitchellh/reflectwalk v1.0.0
go: downloading github.com/Masterminds/goutils v1.1.0
go: downloading github.com/samfoo/ansi v0.0.0-20160124022901-b6bd2ded7189
go: downloading golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e
go: downloading github.com/manifoldco/promptui v0.3.1
go: downloading github.com/Masterminds/semver v1.4.2
go: downloading github.com/Masterminds/semver/v3 v3.1.0
go: downloading golang.org/x/text v0.3.3
go: downloading github.com/huandu/xstrings v1.3.1
go: downloading gopkg.in/yaml.v2 v2.3.0
go: downloading github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1
go: downloading github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a
go: downloading github.com/mattn/go-colorable v0.1.6
go: downloading github.com/antlr/antlr4 v0.0.0-20200503195918-621b933c7a7f
go: downloading github.com/lucas-clemente/quic-go v0.19.3
go: downloading github.com/smallstep/nosql v0.3.0
go: downloading github.com/mattn/go-isatty v0.0.12
go: downloading github.com/cpuguy83/go-md2man v1.0.10
go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.0
go: downloading google.golang.org/genproto v0.0.0-20200806141610-86f49bd18e98
go: downloading github.com/shurcooL/sanitized_anchor_name v1.0.0
go: downloading github.com/cheekybits/genny v1.0.0
go: downloading github.com/russross/blackfriday v1.5.2
go: downloading github.com/dgraph-io/badger v1.5.3
go: downloading github.com/russross/blackfriday/v2 v2.0.1
go: downloading github.com/marten-seemann/qpack v0.2.1
go: downloading github.com/dgraph-io/badger/v2 v2.0.1-rc1.0.20200413122845-09dd2e1a4195
go: downloading github.com/lunixbochs/vtclean v1.0.0
go: downloading github.com/marten-seemann/qtls-go1-15 v0.1.1
go: downloading github.com/go-sql-driver/mysql v1.5.0
go: downloading gopkg.in/natefinch/lumberjack.v2 v2.0.0
go: downloading github.com/dgraph-io/ristretto v0.0.2-0.20200115201040-8f368f2f2ab3
go: downloading github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964
go: downloading github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2
go: downloading github.com/DataDog/zstd v1.4.1
go: downloading go.etcd.io/bbolt v1.3.3
go: downloading github.com/golang/snappy v0.0.1
go: downloading github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9
go: downloading go.step.sm/crypto v0.6.0
go: downloading github.com/sirupsen/logrus v1.6.0
go: downloading github.com/rs/xid v1.2.1
go: downloading gopkg.in/square/go-jose.v2 v2.5.1
go: downloading google.golang.org/grpc v1.27.1
# github.com/DataDog/zstd
cgo: exec /missing-cc: fork/exec /missing-cc: no such file or directory

Is there some extra arguments required to make this work?

Try setting CGO_ENABLED=0

2 Likes

To clarify, run CGO_ENABLED=0 go build

2 Likes

Yes! that did the trick!

The system seems to freeze but after a few minutes the job is succesfully done!

Thanks!

Hi, i am facing same error but when i run CGO_ENABLED=0 go build , it throws error > The term ‘CGO_ENABLED=0’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
> if a path was included, verify that the path is correct and try again.

can you please help me out here?

Hi @Ankit_Kumar, welcome to the Caddy community!

Are you by any chance trying this in a Windows environment? The above solution worked for me with Debian. If you are using Powershell, you might need a different syntax. Unfortunately I’m not familiar with that so I can’t be much more help.

Edit: This will help you Optional environment variables

1 Like

You’d be better off using xcaddy which wraps all this for you.

thank you for quick reply @Rob789 .
Yes I was trying this on windows.
No worries , thank you .

This topic was automatically closed after 30 days. New replies are no longer allowed.