MacOS中的LIBC 的如何使用(链接)调试版本

How to use (link) debug version of libc++ in macOS?

本文关键字:链接 调试 版本 何使用 中的 LIBC MacOS      更新时间:2023-10-16

我想在macOS中启用 libc++的调试版本,所以我在 cxx_build_flags中定义了 _LIBCPP_DEBUG=1 [libc 的调试版本],但无法链接libc++的调试功能。我想我的系统中只有libc++的发行版本,因此如何在MacOS中获得libc++的调试版本

Undefined symbols for architecture x86_64:
"std::__1::__libcpp_db::__decrementable(void const*) const", referenced from:
  void std::__1::__nth_element<std::__1::__debug_less<std::__1::__less<float, float> >&, std::__1::__wrap_iter<float*> >(std::__1::__wrap_iter<float*>, std::__1::__wrap_iter<float*>, std::__1::__wrap_iter<float*>, std::__1::__debug_less<std::__1::__less<float, float> >&)

我想我可以工作!

所以我采取的步骤,

  1. 检查您的工具链__config是否为_LIBCPP_VERSION的值。
  2. 浏览设置该版本的提交的源回购
  3. 从该提交中,找到debug.cpp文件
  4. 包括/compile/link debug.cpp与您的项目(并记住设置_LIBCPP_DEBUG=1(。

对我来说,这些步骤的中间结果为(使用Catalina,Xcode版本11.3.1(

  • /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__config在版本8000
  • 在https://github.com/llvm/llvm-project/commits/main?&ppath [] = libcxx&amp;path []///github.com/llvm/llvm-project/commit/25977548AA5AD7CFE45A17E4BA136ABFA4613B9B96#DIFF-0A85F740CD20222220254BBC3BBBBBBBBBBBB03975C89D93A3A3A3A3AA >
  • 该提交的debug.cpp在https://github.com/llvm/llvm/llvm-project/blob/259777548aaaaaa5ad7cfe45a17e4ba136abfa4613b9b966666666666666666/libcxxxx/srcx/src/src/deebug.cpp

我尝试在没有更多详细信息的情况下重新激活此线程。

我也有同样的问题。这很容易复制:

#include <string>
int main()
{
  std::string name;
  return 0;
}

然后与:

编译
clang++ -D_LIBCPP_DEBUG=1 main.cpp

我们获得:

Undefined symbols for architecture x86_64:
  "std::__1::__libcpp_db::__insert_c(void*)", referenced from:
      void std::__1::__libcpp_db::__insert_c<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in main-7ff3c5.o
  "std::__1::__libcpp_db::__erase_c(void*)", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string() in main-7ff3c5.o
  "std::__1::__c_node::~__c_node()", referenced from:
      std::__1::_C_node<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::~_C_node() in main-7ff3c5.o
  "std::__1::__get_db()", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string() in main-7ff3c5.o
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string() in main-7ff3c5.o
  "typeinfo for std::__1::__c_node", referenced from:
      typeinfo for std::__1::_C_node<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > in main-7ff3c5.o
  "vtable for std::__1::__c_node", referenced from:
      std::__1::__c_node::__c_node(void*, std::__1::__c_node*) in main-7ff3c5.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

,如果我使用brew的g++-9 Providen(真正的G 而不是伪装的Apple Clang编译器(,它将编译并完美运行。

忘记使用libc 的调试模式,它是唯一的解决方案吗?

nb:我在https://forums.developer.apple.com/thread/99194中看到了同样的问题仍然没有答案。