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=address
option is used to link a program, the GCC driver automatically links againstlibasan
. Iflibasan
is available as a shared library, and the-static
option is not used, then this links against the shared version oflibasan
. The-static-libasan
option directs the GCC driver to linklibasan
statically, without necessarily linking other libraries statically.