{"record":{"id":"731dbe8536bc3adc","repo":"golang/go","slug":"mixing-of-meta-and-non-meta-packages-is-not-allowe","errorCode":null,"errorMessage":"mixing of meta and non-meta packages is not allowed","messagePattern":"mixing of meta and non-meta packages is not allowed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/build.go","lineNumber":685,"sourceCode":"\tif len(libname) == 0 { // non-meta packages only. use import paths\n\t\tif len(args) == 1 && strings.HasSuffix(args[0], \"/...\") {\n\t\t\t// Special case of \"foo/...\" as mentioned above.\n\t\t\targ := strings.TrimSuffix(args[0], \"/...\")\n\t\t\tif build.IsLocalImport(arg) {\n\t\t\t\tcwd, _ := os.Getwd()\n\t\t\t\tbp, _ := cfg.BuildContext.ImportDir(filepath.Join(cwd, arg), build.FindOnly)\n\t\t\t\tif bp.ImportPath != \"\" && bp.ImportPath != \".\" {\n\t\t\t\t\targ = bp.ImportPath\n\t\t\t\t}\n\t\t\t}\n\t\t\tappendName(strings.ReplaceAll(arg, \"/\", \"-\"))\n\t\t} else {\n\t\t\tfor _, pkg := range pkgs {\n\t\t\t\tappendName(strings.ReplaceAll(pkg.ImportPath, \"/\", \"-\"))\n\t\t\t}\n\t\t}\n\t} else if haveNonMeta { // have both meta package and a non-meta one\n\t\treturn \"\", errors.New(\"mixing of meta and non-meta packages is not allowed\")\n\t}\n\t// TODO(mwhudson): Needs to change for platforms that use different naming\n\t// conventions...\n\treturn \"lib\" + libname + \".so\", nil\n}\n\nfunc runInstall(ctx context.Context, cmd *base.Command, args []string) {\n\tmoduleLoader := modload.NewLoader()\n\tfor _, arg := range args {\n\t\tif strings.Contains(arg, \"@\") && !build.IsLocalImport(arg) && !filepath.IsAbs(arg) {\n\t\t\tinstallOutsideModule(moduleLoader, ctx, args)\n\t\t\treturn\n\t\t}\n\t}\n\n\tmoduleLoader.InitWorkfile()\n\tBuildInit(moduleLoader)\n\tpkgs := load.PackagesAndErrors(moduleLoader, ctx, load.PackageOpts{AutoVCS: true}, args)","sourceCodeStart":667,"sourceCodeEnd":703,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/build.go#L667-L703","documentation":"Thrown by libname() in cmd/go/internal/work during -buildmode=shared (building a shared library from a set of packages). It fires when the package arguments contain both a meta-package wildcard (\"all\", \"std\", \"cmd\", or \"...\"-style patterns recognized by search.IsMetaPackage) and an explicit non-meta package or import path. The shared-library name is derived from the package set, and mixing the two forms is structurally ambiguous, so the go command rejects it.","triggerScenarios":"Running `go install -buildmode=shared std example.com/lib` or `go build -buildmode=shared all ./mymod`. Any -buildmode=shared invocation whose args list contains at least one of all/std/cmd/... and at least one concrete import path or directory.","commonSituations":"Trying to bundle the standard library together with a project library into one .so. CI scripts that prepend \"std\" to a package list to share stdlib. Misuse of wildcard patterns combined with explicit deps.","solutions":["Split into two separate -buildmode=shared invocations: one for the meta-package set, one for the explicit packages.","Replace the meta-package with its explicit expansion (e.g. list packages under std with `go list std` and pass those import paths together with your own).","Drop the wildcard and pass only the concrete import paths you actually want in the shared library.","Reconsider -buildmode=shared — it is niche; -buildmode=plugin or a regular archive may fit the goal better."],"exampleFix":"# before\nGOFLAGS=-buildmode=shared\ngo install -buildmode=shared std example.com/mylib\n# after\ngo install -buildmode=shared std\ngo install -buildmode=shared example.com/mylib","handlingStrategy":"validation","validationCode":"func validateSharedArgs(args []string) error {\n    hasMeta, hasNonMeta := false, false\n    for _, a := range args {\n        if search.IsMetaPackage(a) { hasMeta = true } else { hasNonMeta = true }\n    }\n    if hasMeta && hasNonMeta {\n        return errors.New(\"do not mix meta-package patterns with explicit import paths under -buildmode=shared\")\n    }\n    return nil\n}","typeGuard":"func argsAreHomogeneous(args []string) bool {\n    saw := 0\n    for _, a := range args {\n        cur := 1\n        if search.IsMetaPackage(a) { cur = 2 }\n        if saw == 0 { saw = cur } else if saw != cur { return false }\n    }\n    return true\n}","tryCatchPattern":null,"preventionTips":["Under -buildmode=shared, pass either all-meta or all-explicit args — never both.","Replace meta-packages with `go list` output when you need fine control.","Consider whether -buildmode=shared is really needed; it is rarely the right choice."],"tags":["go-toolchain","buildmode","shared","packages","validation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}