<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection">
<div dir="auto">This is the expected behaviour.
<div dir="auto"><br /></div>
<div dir="auto">As you already discovered, it is possible to control the compilation and link steps with variables as described in <a href="https://cmake.org/cmake/help/git-master/module/CheckCXXSourceCompiles.html#module:CheckCXXSourceCompiles">https://cmake.org/cmake/help/latest/module/CheckCXXSourceCompiles.html#module:CheckCXXSourceCompiles</a>.</div>
<div dir="auto"><br /></div>
<div dir="auto">To specify, in a more clean way, link options, use preferably the variable CMAKE_REQUIRED_LINK_OPTIONS.</div>
<div dir="auto"><br /></div>
</div>
</div>
<div name="messageReplySection">Le 24 oct. 2019 à 22:42 +0200, Michael Ellery <mellery451@gmail.com>, a écrit :<br />
<blockquote type="cite" class="spark_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">I’ve dealt with that using something like this:<br />
<br />
set (_saved_CRL ${CMAKE_REQUIRED_LIBRARIES})<br />
set (CMAKE_REQUIRED_LIBRARIES “-fsanitize=address;asan")<br />
check_cxx_compiler_flag (-fsanitize=address COMPILER_SUPPORTS_SAN)<br />
set (CMAKE_REQUIRED_LIBRARIES ${_saved_CRL})<br />
<br />
the second item in CMAKE_REQUIRED_LIBRARIES is only needed when using gcc which also requires a -lasan when linking (clang does not need this)<br />
<br />
<blockquote type="cite" class="spark_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">On Oct 24, 2019, at 12:47 PM, Turner, Adrian Keith via CMake <cmake@cmake.org> wrote:<br />
<br />
Hi CMake Mailing List,<br />
<br />
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.<br />
<br />
To test this I tried compiling the following program:<br />
int main() {};<br />
<br />
This compiled with the following commands:<br />
<blockquote type="cite" class="spark_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #3498db;">g++ -fsanitize=address -c test.cpp<br />
g++ -fsanitize=address test.o -o test.exe<br /></blockquote>
<br />
And fails with the same error message as CHECK_CXX_COMPILER_FLAG when I compile with:<br />
<blockquote type="cite" class="spark_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #3498db;">g++ -fsanitize=address -c test.cpp<br />
g++ test.o -o test.exe<br /></blockquote>
<br />
producing the following message:<br />
Undefined symbols for architecture x86_64:<br />
"___asan_init", referenced from:<br />
__GLOBAL__sub_I_00099_0_test.cpp in test.o<br />
"___asan_version_mismatch_check_v8", referenced from:<br />
__GLOBAL__sub_I_00099_0_test.cpp in test.o<br />
ld: symbol(s) not found for architecture x86_64<br />
collect2: error: ld returned 1 exit status<br />
<br />
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?<br />
<br />
Many thanks<br />
Adrian Turner<br />
<br />
<br />
--<br />
<br />
Powered by www.kitware.com<br />
<br />
Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ<br />
<br />
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br />
<br />
CMake Support: http://cmake.org/cmake/help/support.html<br />
CMake Consulting: http://cmake.org/cmake/help/consulting.html<br />
CMake Training Courses: http://cmake.org/cmake/help/training.html<br />
<br />
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html<br />
<br />
Follow this link to subscribe/unsubscribe:<br />
https://cmake.org/mailman/listinfo/cmake<br /></blockquote>
<br />
--<br />
<br />
Powered by www.kitware.com<br />
<br />
Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ<br />
<br />
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br />
<br />
CMake Support: http://cmake.org/cmake/help/support.html<br />
CMake Consulting: http://cmake.org/cmake/help/consulting.html<br />
CMake Training Courses: http://cmake.org/cmake/help/training.html<br />
<br />
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html<br />
<br />
Follow this link to subscribe/unsubscribe:<br />
https://cmake.org/mailman/listinfo/cmake<br /></blockquote>
</div>
</body>
</html>