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

**Code:** `ODR violation` · **Category:** C/C++ · **Seen on:** C/C++

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/odr-violation)
