{"record":{"id":"5576026abc879c48","repo":"nodejs/node","slug":"multiple-def-files","errorCode":null,"errorMessage":"Multiple .def files","messagePattern":"Multiple \\.def files","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/gyp/msvs_emulation.py","lineNumber":619,"sourceCode":"        lib(\n            \"TargetMachine\",\n            map={\"1\": \"X86\", \"17\": \"X64\", \"3\": \"ARM\"},\n            prefix=\"/MACHINE:\",\n        )\n        lib(\"AdditionalOptions\")\n        return libflags\n\n    def GetDefFile(self, gyp_to_build_path):\n        \"\"\"Returns the .def file from sources, if any.  Otherwise returns None.\"\"\"\n        spec = self.spec\n        if spec[\"type\"] in (\"shared_library\", \"loadable_module\", \"executable\"):\n            def_files = [\n                s for s in spec.get(\"sources\", []) if s.lower().endswith(\".def\")\n            ]\n            if len(def_files) == 1:\n                return gyp_to_build_path(def_files[0])\n            elif len(def_files) > 1:\n                raise Exception(\"Multiple .def files\")\n        return None\n\n    def _GetDefFileAsLdflags(self, ldflags, gyp_to_build_path):\n        \"\"\".def files get implicitly converted to a ModuleDefinitionFile for the\n        linker in the VS generator. Emulate that behaviour here.\"\"\"\n        if def_file := self.GetDefFile(gyp_to_build_path):\n            ldflags.append('/DEF:\"%s\"' % def_file)\n\n    def GetPGDName(self, config, expand_special):\n        \"\"\"Gets the explicitly overridden pgd name for a target or returns None\n        if it's not overridden.\"\"\"\n        config = self._TargetConfig(config)\n        output_file = self._Setting((\"VCLinkerTool\", \"ProfileGuidedDatabase\"), config)\n        if output_file:\n            output_file = expand_special(\n                self.ConvertVSMacros(output_file, config=config)\n            )\n        return output_file","sourceCodeStart":601,"sourceCodeEnd":637,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/gyp/msvs_emulation.py#L601-L637","documentation":"GetDefFile scans the target's sources for files ending in '.def' (module-definition files for the MSVC linker). A single .def is accepted and wired into linker flags; more than one is ambiguous and rejected, because the linker can only consume one definition file.","triggerScenarios":"A target of type shared_library, loadable_module, or executable has two or more source files whose lowercased name ends with '.def'.","commonSituations":"Accidentally adding two .def files to sources; merging sources from another target that already contributed a .def; build tooling that drops a generated .def next to a hand-written one.","solutions":["Find all '.def' files listed in the target's 'sources' and keep only the one you intend the linker to use.","Remove the extra .def entries (or move them out of sources).","Re-run gyp."],"exampleFix":"// before\n'sources': ['lib.def', 'other.def', 'main.c']\n// after\n'sources': ['lib.def', 'main.c']","handlingStrategy":"validation","validationCode":"def_files = [s for s in target_dict.get('sources', []) if s.lower().endswith('.def')]\nif target_dict.get('type') in ('shared_library', 'loadable_module', 'executable') and len(def_files) > 1:\n    raise ValueError(f'{target_dict[\"target_name\"]}: multiple .def files: {def_files}')","typeGuard":"def at_most_one_def_file(target_dict: dict) -> bool:\n    def_files = [s for s in target_dict.get('sources', []) if s.lower().endswith('.def')]\n    return len(def_files) <= 1","tryCatchPattern":null,"preventionTips":["Designate exactly one .def as the linker definition per target.","If multiple modules need exports, merge them into a single .def.","Review sources lists after merging targets."],"tags":["gyp","msvs","def-file","duplicate"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}