gpt4 book ai didi

c++ - 带 CMake 的 LLVM 地址 sanitizer

转载 作者:搜寻专家 更新时间:2023-10-31 00:27:50 28 4
gpt4 key购买 nike

我正在尝试使用带有 -fsanitize=address 选项的 clang 编译最简单的可执行文件。直接使用 clang 来做到这一点非常简单。但我的观点是通过 CMake 来完成。

这就是我的做法。CMakeLists.txt 文件:

cmake_minimum_required(VERSION 3.5.1 FATAL_ERROR)
project(TestSanitizer VERSION 0.1.0 LANGUAGES CXX)
add_executable(Test main.cpp)
target_compile_options(Test PUBLIC
-std=c++17
-Werror
-Weverything
-Wno-c++98-compat
-Wno-c++98-c++11-c++14-compat
-Wno-c++98-compat-pedantic
-fsanitize=address)

主要.cpp:

int main(int, const char**) { return 0; }

使用 bash 脚本 (config_gen_build.sh) 配置和制作:

if [ -d "bin" ]; then
rm -rf bin
fi

mkdir bin
cd bin

#config and gen
export CC=/usr/bin/clang-5.0
export CXX=/usr/bin/clang++-5.0
cmake ./../

#build
make

最后,我得到的错误: enter image description here

这是怎么回事?我应该链接到一些图书馆吗?

最佳答案

与地址清理器链接的最简单方法是将 -fsanitize=address 指定为链接器以及编译器选项。这会导致 clang 或 gcc 将正确的库和标志传递给链接器。

关于c++ - 带 CMake 的 LLVM 地址 sanitizer ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47603005/

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