[CMake] CHECK_CXX_COMPILER_FLAG doesn't give correct result for -fsanitize=address
Turner, Adrian Keith
akt at lanl.gov
Thu Oct 24 15:47:19 EDT 2019
Hi CMake Mailing List,
I am using the CHECK_CXX_COMPILER_FLAG directive in a CMake file to detect whether the compiler uses the "-fsanitize=address" compiler flag. I'm using the g++ 7.3.0 compiler which supports this flag but the CHECK_CXX_COMPILER_FLAG directive incorrectly determines that this flag is not supported.
To test this I tried compiling the following program:
int main() {};
This compiled with the following commands:
> g++ -fsanitize=address -c test.cpp
> g++ -fsanitize=address test.o -o test.exe
And fails with the same error message as CHECK_CXX_COMPILER_FLAG when I compile with:
> g++ -fsanitize=address -c test.cpp
> g++ test.o -o test.exe
producing the following message:
Undefined symbols for architecture x86_64:
"___asan_init", referenced from:
__GLOBAL__sub_I_00099_0_test.cpp in test.o
"___asan_version_mismatch_check_v8", referenced from:
__GLOBAL__sub_I_00099_0_test.cpp in test.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
It seems that CHECK_CXX_COMPILER_FLAG doesn't add the flag to the linking command when it tests compilation. Is this a bug with CHECK_CXX_COMPILER_FLAG or is there something I'm missing?
Many thanks
Adrian Turner
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20191024/b28e260a/attachment-0001.html>
More information about the CMake
mailing list