gpt4 book ai didi

cmake - 如何在 CMake 中设置 ASAN_OPTIONS 环境变量?

转载 作者:行者123 更新时间:2023-12-04 07:40:18 24 4
gpt4 key购买 nike

据我了解,使用 ASAN_OPTIONS随着 clang ,ASAN_OPTIONS编译前必须设置环境变量。
如何在不添加包装脚本的情况下在 CMake 脚本中执行此操作?
仅当使用 clang 编译时,我才需要禁用对一个特定测试项目的 ODR 违规检查。所以在CMakeLists.txt我有文件:

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Clange reports ODR Violation errors in mbedtls/library/certs.c. Need to disable this check.
set(ENV{ASAN_OPTIONS} detect_odr_violation=0)
endif()
但是运行后 cmake ,如果我输入 echo $ASAN_OPTIONS ,未设置。
运行后 cmake ,如果我输入:
export ASAN_OPTIONS=detect_odr_violation=0
make
一切都很好。 cmake可以吗?设置一个环境变量,使其在 cmake 之后仍然存在跑?抱歉,我对环境的理解有限!

最佳答案

As far as I understand, to use ASAN_OPTIONS with clang,the ASAN_OPTIONS environment variable must be set before compiling.


不是真的, ASAN_OPTIONS不会以任何方式影响编译。相反,它控制已编译代码的行为,因此需要在运行测试之前进行设置(和导出)。
在您的情况下,使用不同的控制机制会更容易: __asan_default_options callback :
#ifndef __has_feature
// GCC does not have __has_feature...
#define __has_feature(feature) 0
#endif

#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
#ifdef __cplusplus
extern "C"
#endif
const char *__asan_default_options() {
// Clang reports ODR Violation errors in mbedtls/library/certs.c.
// NEED TO REPORT THIS ISSUE
return "detect_odr_violation=0";
}
#endif

关于cmake - 如何在 CMake 中设置 ASAN_OPTIONS 环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67512498/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com