Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
GCC sanitizer with CMake

Build in CMake with these params:

CMAKE_CXX_FLAGS:STRING= -fsanitize=address  -fsanitize=leak -g
CMAKE_C_FLAGS:STRING=-fsanitize=address  -fsanitize=leak -g
CMAKE_EXE_LINKER_FLAGS:STRING=-fsanitize=address  -fsanitize=leak
CMAKE_MODULE_LINKER_FLAGS:STRING=-fsanitize=address  -fsanitize=leak

Which can be done with:

cmake .. -DCMAKE_CXX_FLAGS="-fsanitize=address  -fsanitize=leak -g" -DCMAKE_C_FLAGS="-fsanitize=address  -fsanitize=leak -g" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address  -fsanitize=leak" -DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=address  -fsanitize=leak"

Then run with:

export ASAN_OPTIONS=fast_unwind_on_malloc=0
Copy link

cryptid11 commented Nov 19, 2019

these seems to not work if i have a Makefile instead of a CMakeLists.txt.
I think this should work tought if you put this at the beginning of the file: (deny/confirm?)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak -g")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment