Linux 我应该使用 libc++ 还是 libstdc++?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14972425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 19:04:31  来源:igfitidea点击:

Should I use libc++ or libstdc++?

linuxmacosopencvlibstdc++libc++

提问by Loozie

I am developing command line interface executables for both osx and linux using c/c++. The project will link against opencv. Should I use libc++ or libstdc++?

我正在使用 c/c++ 为 osx 和 linux 开发命令行界面可执行文件。该项目将链接到 opencv。我应该使用 libc++ 还是 libstdc++?

采纳答案by Jonathan Wakely

I would use the native library for each OS i.e. libstdc++ on GNU/Linux and libc++ on Mac OS X.

我会为每个操作系统使用本机库,即 GNU/Linux 上的 libstdc++ 和 Mac OS X 上的 libc++。

libc++ is not 100% complete on GNU/Linux, and there's no real advantage to using it when libstdc++ is more complete. Also, if you want to link to any other libraries written in C++ they will almost certainly have been built with libstdc++ so you'll need to link with that too to use them.

libc++ 在 GNU/Linux 上不是 100% 完整的,当 libstdc++ 更完整时,使用它并没有真正的优势。此外,如果您想链接到任何其他用 C++ 编写的库,它们几乎肯定是用 libstdc++ 构建的,因此您也需要与之链接才能使用它们。

More info hereabout the completeness of libc++ on various platforms.

有关libc++ 在各种平台上的完整性的更多信息,请点击此处

回答by Mario Vazquez

Major Linux distributions do not provide LLVM libc++, because:

主要的 Linux 发行版不提供 LLVM libc++,因为:

  1. Unlike Apple and FreeBSD, the GPL+3 is not an issue, so no need to implement another stack here.
  2. Linux components have been developed around GNU libstd++ for ages. Some of them do not build on anything else.
  3. While libc++ is strong in new features, it has some problems with legacy code.
  1. 与 Apple 和 FreeBSD 不同,GPL+3 不是问题,因此无需在此处实现其他堆栈。
  2. Linux 组件已经围绕 GNU libstd++ 开发了很长时间。其中一些不建立在其他任何东西上。
  3. 虽然 libc++ 在新特性方面很强大,但它在遗留代码方面存在一些问题。

If eventually libc++ became part of distributions, it will be as an optional component. linking against it will probably require extra options.

如果最终 libc++ 成为发行版的一部分,它将作为可选组件。链接它可能需要额外的选项。

Like Jonathan said, you should use whatever tool is included by default. Clang is safe in Linux to use since is configured as a GCC replacement, so in that aspect you don't have to worry about 2 compilers. Also since you are targeting two platforms, you should take a look to cmake.

就像乔纳森说的,你应该使用默认包含的任何工具。Clang 在 Linux 中使用是安全的,因为它被配置为 GCC 替代品,所以在这方面你不必担心 2 个编译器。此外,由于您的目标是两个平台,因此您应该看看 cmake。

回答by DAG

it is said libc++ has more human readable error messages on template errors.

据说 libc++ 有更多关于模板错误的人类可读错误消息。