MacOS - clang地址清理程序无法链接

时间:2017-10-24 00:55:40

标签: macos cmake clang linker-errors address-sanitizer

我一直在尝试使用Clang的地址代码清理程序,但链接器不会使用它。链接器可能是“ld”,但我的CMAKE设置向我保证clang是链接器。

为编译器和链接器标志添加了-fsanitize=address

错误:

Undefined symbols for architecture x86_64:
___asan_after_dynamic_init
...
___asan_before_dynamic_init
...
etc.
ld: symbol(s) not found for architecture x86_64    <<<< **suspicious**
clang: error: linker command failed with exit code 1 (use -v to see invocation)
  • 环境:MacOS
  • clang:Apple LLVM 8.0.0版(clang-800.0.38)
  • cmake:3.7.1

  • CMAKE_CXX_COMPILER = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++(重定向到clang)

  • CMAKE_CXX_COMPILER_ID = Clang
  • 编译器标志:-O0 -g -fsanitize = address
  • CMAKE_LINKER = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++(重定向到clang)
  • CMAKE_CXX_LINK_EXECUTABLE = CMAKE_CXX_COMPILER标记CMAKE_CXX_LINK_FLAGS LINK_FLAGS OBJECTS -o TARGET LINK_LIBRARIES
  • CMAKE_CXX_LINK_FLAGS = -Wl,-search_paths_first -Wl,-headerpad_max_install_names -fsanitize = address -v

1 个答案:

答案 0 :(得分:1)

来自here

的解决方案
  

将-fsanitize = address标志传递给链接器以及编译器。

-DCMAKE_EXE_LINKER_FLAGS =“-fsanitize = address”