Search code examples
gccaddress-sanitizer

"undefined reference" errors when trying to use address sanitizer with GCC


I'm trying to build my project with

g++ -O0 -g -fsanitize=address -fno-omit-frame-pointer

but get lots of errors like:

/home/user/libs/opencv/include/opencv2/core/mat.hpp:715: undefined reference to `__asan_report_load8'

How to compile project with AddressSanitize support?

My gcc version is 4.8.4.


Solution

  • You need to add the switch -lasan -fsanitize=address to your both your compile and link command line to link the correct library.

    Note: the original answer -lasan is outdated and should not be used, as per comments