[英]CLion wont run binary with address sanitizer
I'm using CLion IDE, Cmake with GCC compiler and I'm trying to run binary with address sanitizer.我正在使用 CLion IDE、带有 GCC 编译器的 Cmake,并且正在尝试使用地址清理程序运行二进制文件。 I followed this: What's the proper way to enable AddressSanitizer in CMake that works in Xcode and added
我遵循了这个: 在 Xcode 中启用 AddressSanitizer 的正确方法是什么,并添加了
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
to CMakeLists.txt file and then got an error when running the binary in CLion using the run button:到 CMakeLists.txt 文件,然后使用运行按钮在 CLion 中运行二进制文件时出错:
==22084==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
When I run the binary via terminal, it works as it should be.当我通过终端运行二进制文件时,它可以正常工作。 It doesn't work in CLion's run window.
它在 CLion 的运行窗口中不起作用。 https://imgur.com/a/MXOM7BJ
https://imgur.com/a/MXOM7BJ
Edit: The solution was adding LD_PRELOAD=libasan.so.5
to environment variables of CLion.编辑:解决方案是将
LD_PRELOAD=libasan.so.5
添加到 CLion 的环境变量中。
My CMakeLists.txt:我的 CMakeLists.txt:
cmake_minimum_required(VERSION 3.17)
project(Playground)
set(CMAKE_CXX_STANDARD 14)
add_executable(Playground main.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
What's happening?发生了什么?
Adding these lines from the stackoverflow thread to CMakeLists.txt file didnt work too.将这些行从 stackoverflow 线程添加到 CMakeLists.txt 文件也不起作用。
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-fsanitize=address -fno-omit-frame-pointer")
and this line from this guide https://www.jetbrains.com/help/clion/google-sanitizers.html#LSanChapter also didnt work本指南中的这一行https://www.jetbrains.com/help/clion/google-sanitizers.html#LSanChapter也不起作用
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -O1")
Then I tried adding LD_TRACE_LOADED_OBJECTS=1
to CLion environment variables and nothing changed.然后我尝试将
LD_TRACE_LOADED_OBJECTS=1
添加到 CLion 环境变量中,但没有任何改变。
My ldd ./file
command output of the binary:我的
ldd ./file
命令输出二进制文件:
linux-vdso.so.1 (0x00007ffd82d96000)
libgtk3-nocsd.so.0 => /lib/x86_64-linux-gnu/libgtk3-nocsd.so.0 (0x00007f7d532e1000)
libasan.so.5 => /lib/x86_64-linux-gnu/libasan.so.5 (0x00007f7d528af000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7d526bd000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7d526b7000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7d52694000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f7d52689000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7d52538000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7d5251d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7d5350c000)
The problem is caused by the LD_PRELOAD=libgtk3-nocsd.so.0
setting somewhere in your environment.该问题是由环境中某处的
LD_PRELOAD=libgtk3-nocsd.so.0
设置引起的。 Overwrite it or unset the variable in your CLion run configuration.覆盖它或取消设置 CLion 运行配置中的变量。
First remove all of the set commands you added, and then add these commands before the compile:首先删除所有你添加的set命令,然后在编译之前添加这些命令:
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.