How to enable sanitizers in QMake?
Asked Answered
C

1

18

How do I enable usage of sanitizers in QMake's .pro files?

I found several ressources that modify QMAKE_CXXFLAGS themselves but the introductory blogpost says:

It is scheduled for the dev branch (Qt 5.2) because it’s a new feature, but you should be fine cherry-picking it to e.g. Qt 5.0. You can then configure Qt with -address-sanitizer, and run qmake CONFIG+=address_sanitizer for your own applications.

However, adding CONFIG+=address_sanitizer does not seem to have an effect.

Comforter answered 19/8, 2016 at 14:12 Comment(0)
C
34

To enable, e.g., address sanitizer you have to write:

CONFIG += sanitizer sanitize_address

The sanitizer options are defined in Qt's mkspecs (mkspecs/features/sanitizer.prf and mkspecs/common/sanitize.conf), which gets loaded when you add CONFIG += sanitizer. A quick look into my sanitizer.prf (Qt 5.7.0) shows that the specific sanitizers are:

  • sanitize_address
  • sanitize_memory
  • sanitize_thread
  • sanitize_undefined
Comforter answered 19/8, 2016 at 14:12 Comment(1)
The exact string I had to add is CONFIG+=sanitizer CONFIG+=sanitize_address.Strategy

© 2022 - 2024 — McMap. All rights reserved.