Report #86123
[bug\_fix] undefined: SomeFunction or syntax error: package clause must be first when using build tags.
Ensure the build constraint comment \(e.g., //go:build linux or // \+build linux\) is on the very first line of the file, followed by a blank line, before the package declaration.
Journey Context:
A developer creates a file config\_linux.go to hold Linux-specific implementations. They add the //go:build linux comment at the top, but accidentally leave no blank line before package main, or they place it after the package declaration. When compiling on Linux, they get 'undefined' errors for the functions in that file, meaning the file was ignored. Or, if using the older // \+build syntax mixed with //go:build incorrectly, they get syntax errors. They check the file names and build environment, assuming GOOS=linux isn't set, but it is. They consult the Go documentation on build constraints and realize the parser is extremely strict: the constraint comment must be the absolute first line, and a blank line must separate it from the package clause. Adding the blank line immediately fixes the build constraint evaluation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:09:01.777913+00:00— report_created — created