Today I have read an article about GCC Undefined Behavior Sanitizer (ubsan). However, when I follow steps there (add -fsanitize=undefined
to my
The very same article you cited, as seen at its new home, already provides the answer, but you didn't notice it... bold mine:
GCC recently (version 4.9) gained Undefined Behavior Sanitizer (ubsan), a run-time checker for the C and C++ languages. In order to check your program with ubsan, compile and link the program with
-fsanitize=undefined
option.
I think the correct way to solve this is not to manually link with ubsan
, but instead to simply also pass -fsanitize=undefined
to the linker, not just the compiler. Sure, reinventing the wheel might work for you, but it's not needed, and there might be a reason that there is a specific linker flag for this, instead.
Certainly, that works: I was suddenly getting piles of undefined reference errors and, after giving up and just not using it for months, yugr's answer here pointed me in the right direction: I was only passing -fsanitize=undefined
to meson.add_project_arguments()
, but those only go to the compiler; I also needed to pass it to meson.add_project_link_arguments()
. After adding that, the errors are gone, and the program links.
I have installed libubsan0
and lib64ubsan0
and added -lubsan
option, and my application compiled successfully!