Conan2 & compiler sanitizers

200 views Asked by At

How to use compiler sanitizers, especially the address sanitizer in Conan2? Searching on Google, the only result found is for version 1, which does not work on 2. I tried the profile below, but without success.

include(default)

[settings]
arch=wasm
os=Emscripten

compiler.sanitizer=Address

[tool_requires]
*: emsdk/3.1.44

[env]
CFLAGS=-fsanitize=address
CXXFLAGS=-fsanitize=address
LDFLAGS=-fsanitize=address

And:

[compiler_flags]
sanitizer=Address

Conan says that env or compiler_flags is not a recognized section.

1

There are 1 answers

2
SpacePotatoes On BEST ANSWER

To add custom flags to compiler and linker in conan v2:

include(default)

[settings]
arch=wasm
os=Emscripten

[tool_requires]
*: emsdk/3.1.44

[conf]
tools.build:cflags=["-fsanitize=address"]
tools.build:cxxflags=["-fsanitize=address"]
tools.build:exelinkflags=["-fsanitize=address"]
tools.build:sharedlinkflags=["-fsanitize=address"]

If you want that these flags contribute to package id, add this to ~/.conan2/global.conf:

tools.info.package_id:confs=["tools.build:cflags", "tools.build:cxxflags", "tools.build:exelinkflags", "tools.build:sharedlinkflags"]