Autofix Multiple Def

Fixes 'multiple definition' linker errors by removing duplicate symbols.

hyz0906 Updated

File contents

Multiple Definition Skill

Fixes linker errors where the same symbol is defined in multiple translation units.

Detection Patterns

  • multiple definition of 'X'
  • already defined in
  • duplicate symbol

Strategy

  1. Identify Symbol: Extract the duplicated symbol.
  2. Find Definitions: Locate all places where it's defined.
  3. Remove Duplicates: Keep one, remove or fix others.

Instructions

Step 1: Parse Error

From: multiple definition of 'globalVar'; first defined in a.o

Step 2: Common Causes & Fixes

Global variable in header:

// Wrong: header.h
int globalVar = 0;  // Defined in every .cpp that includes

// Fix Option 1: extern declaration
// header.h
extern int globalVar;
// source.cpp
int globalVar = 0;

// Fix Option 2: inline (C++17)
inline int globalVar = 0;

Function defined in header:

// Wrong
void foo() { ... }  // in header

// Fix: make inline
inline void foo() { ... }

Same source compiled twice: Check build file for duplicate source file entries.

hyz0906/autofix_skills/tree/main/claude_skills/linkage_dependency/multiple-def commit 7a9f457c03

Frequently asked questions

npx skillmds@latest add hyz0906/autofix-multiple-def