From ASan's wiki:
Q: I'm getting following error when building my code:
gcc: error: cannot specify -static with -fsanitize=address.A: ASan doesn't work with static linkage. You need to disable static linkage in order to use ASan on your code.
There's a bit of an inconsistency in GCC documentation for -static-libasan though:
When the
-fsanitize=addressoption is used to link a program, the GCC driver automatically links againstlibasan. Iflibasanis available as a shared library, and the-staticoption is not used, then this links against the shared version oflibasan. The-static-libasanoption directs the GCC driver to linklibasanstatically, without necessarily linking other libraries statically.