背景

只在CFLAGS和CXXFLAGS加-fsanitize=address是不够的,会编译失败,报出一堆undefined reference to __asan_report_XXX这样的报错,例如
undefined reference to __asan_report_load1
各种各种......

解决方法

https://stackoverflow.com/a/40215639/16205177
在Cmake里就是

ADD_DEFINITIONS("-fPIC -Wall -fpermissive -fsanitize=address ")
TARGET_LINK_LIBRARIES(...... rt pthread dl -fsanitize=address -Wl,-rpath,'$ORIGIN'/libs)