golang/go · error

%s entry is relative; must be absolute path: %q

Error message

%s entry is relative; must be absolute path: %q

What it means

Returned by checkEnvWrite for CC/CXX when the first token of the split command is neither absolute nor a bare base name (i.e. it contains a path separator but is not absolute). Such paths are unstable because resolution depends on the working directory.

Source

Thrown at src/cmd/go/internal/envcmd/env.go:689

			return fmt.Errorf("GOPATH entry is relative; must be absolute path: %q", val)
		}
	case "GOMODCACHE":
		if !filepath.IsAbs(val) && val != "" {
			return fmt.Errorf("GOMODCACHE entry is relative; must be absolute path: %q", val)
		}
	case "CC", "CXX":
		if val == "" {
			break
		}
		args, err := quoted.Split(val)
		if err != nil {
			return fmt.Errorf("invalid %s: %v", key, err)
		}
		if len(args) == 0 {
			return fmt.Errorf("%s entry cannot contain only space", key)
		}
		if !filepath.IsAbs(args[0]) && args[0] != filepath.Base(args[0]) {
			return fmt.Errorf("%s entry is relative; must be absolute path: %q", key, args[0])
		}
	}

	if !utf8.ValidString(val) {
		return fmt.Errorf("invalid UTF-8 in %s=... value", key)
	}
	if strings.Contains(val, "\x00") {
		return fmt.Errorf("invalid NUL in %s=... value", key)
	}
	if strings.ContainsAny(val, "\v\r\n") {
		return fmt.Errorf("invalid newline in %s=... value", key)
	}
	return nil
}

func readEnvFileLines(mustExist bool) []string {
	file, _, err := cfg.EnvFile()
	if file == "" {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. If the compiler is on $PATH, use just the base name: `go env -w CC=clang`.
  2. Otherwise use an absolute path: `go env -w CC=/opt/toolchains/gcc`.
  3. Install the wrapper somewhere on $PATH and reference it by base name.

Example fix

# before
$ go env -w CC=./wrappers/gcc
error: CC entry is relative; must be absolute path
# after — absolute path
$ go env -w CC="$PWD/wrappers/gcc"
Defensive patterns

Strategy: validation

Validate before calling

parts, _ := quoted.Split(v)
first := parts[0]
if !filepath.IsAbs(first) && first != filepath.Base(first) {
    return fmt.Errorf("CC first token must be absolute or base name: %q", first)
}

Prevention

When it happens

Trigger: `go env -w CC=./gcc`, `go env -w CC=bin/clang`, `go env -w CC=../toolchains/cc`, or any first token with a separator that is not absolute and not a plain base name.

Common situations: Project-local toolchain wrappers; relative wrappers intended to be resolved from $PATH (which already works via base name); monorepo setups referencing sibling directories.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/346d34d6bdb75fcd. Report an issue: GitHub.