Skip to content

cmd/go: CGO compilation fails after upgrading from Go 1.25.5 to 1.25.6 due to --define-variable flag in pkg-config #77387

@DmitriiDunaev

Description

@DmitriiDunaev

Go version

go version go1.25.6 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS='-buildvcs=false'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build168762594=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/code/go.mod'
GOMODCACHE='/go/pkg/mod'
GONOPROXY='git.synesis.ru'
GONOSUMDB='git.synesis.ru'
GOOS='linux'
GOPATH='/go'
GOPRIVATE='git.synesis.ru'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.6'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Issue Description

After upgrading from Go 1.25.5 to Go 1.25.6, our CGO-based code that uses pkg-config with the --define-variable flag no longer compiles. The error occurs during the type checking phase.

Error Message

cmd/gochannel/va/audio/aa/event.go:1: : invalid flag in pkg-config --cflags: --define-variable=prefix=/usr/lib/va/audioanalytics (typecheck)

Affected Code

The issue occurs in a Go file that includes C library bindings:

package aa
// #cgo pkg-config: --define-variable=prefix=/usr/lib/va/audioanalytics audioanalytics
// #include "aa/AudioAnalytics.h"
// extern void audio_logger_go(char* message, void* user_data);
import "C"

Workaround

Setting the environment variable CGO_CFLAGS_ALLOW='.*define.variable.' resolves the compilation issue:

export CGO_CFLAGS_ALLOW='.*define.*variable.*'

pkg-config

The audioanalytics.pc file contains:

prefix=/code/src/AudioAnalytics/AudioAnalyticsClt/build/install
library_dir=libs
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${prefix}/${library_dir}
Name: AudioAnalytics
Description: The AudioAnalytics library
Version: 1.0.7
Libs: -L${libdir} -lAudioAnalyticsLib -ldl -lz -lm -lstdc++
Cflags: -I${includedir}

Questions?

  • Has --define-variable become a disallowed flag in Go 1.25.6?

  • Is this an intentional security restriction, or a regression in flag validation?

  • If --define-variable is now prohibited, what is the recommended approach for overriding pkg-config variables in #cgo pkg-config: directives?

  • Should we file this against the pkg-config tool instead, or is this a Go CGO validation issue?

What did you see happen?

Error Message

cmd/gochannel/va/audio/aa/event.go:1: : invalid flag in pkg-config --cflags: --define-variable=prefix=/usr/lib/va/audioanalytics (typecheck)

What did you expect to see?

Successful build

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.CriticalA critical problem that affects the availability or correctness of production systems built using GoGoCommandcmd/goNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions