ODR violation C/C++ Origin: Application & API OSI layer 7 · Application Last updated 2 Dec 2026

AddressSanitizer: odr-violation: global 'x' at ... / One Definition Rule

The same symbol is defined differently in two translation units or libraries.

Exact message you may see One Definition RuleAddressSanitizer odr-violation
Seen on: C/C++

Meaning

The One Definition Rule requires one definition across the program. Duplicate globals in a static library and a shared library, or classes with different layouts in different files, cause strange crashes; ASan reports odr-violation.

Common causes

  • Same global defined in two shared libraries
  • Header-defined class compiled with different macros per target
  • Static library linked into several shared libraries
  • Inline function with different bodies

⚡ Quick fix

  1. Define globals once and share through one library
  2. Use inline variables or static for file-local data
  3. Compile all targets with the same macros
  4. Use -fvisibility=hidden

Detailed fix by platform

ASan

  1. ASAN_OPTIONS=detect_odr_violation=2 ./app and read both locations in the report

How to diagnose

  1. Locations — Which two files?
  2. Macros — Same defines?
  3. Libs — Duplicate static linking?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

_GLIBCXX_USE_CXX11_ABI — undefined reference to `std::__cxx11::basic_string' — _GLIBCXX_USE_CXX11_ABI mismatch (C/C++)_GLIBCXX_USE_CXX11_ABIalloc-dealloc-mismatch — AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) (C/C++)alloc-dealloc-mismatchattempting double-free — AddressSanitizer: attempting double-free on address (C/C++)attempting double-freeglobal-buffer-overflow — AddressSanitizer: global-buffer-overflow (C/C++)global-buffer-overflowmultiple definition of — C/C++: multiple definition of `x'; first defined here — ld returned 1 exit status (C/C++)multiple definition ofSEGV on unknown address — AddressSanitizer: SEGV on unknown address 0x000000000000 (C/C++)SEGV on unknown addre…stack-buffer-overflow — AddressSanitizer: stack-buffer-overflow on address (C/C++)stack-buffer-overflowstatic initialization order — AddressSanitizer: initialization-order-fiasco / crash before main() in a global constructor (C/C++)static initialization…ODR viola…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.