Should I use libc++ or libstdc++? [closed]
Asked Answered
W

2

116

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++?

Wooldridge answered 20/2, 2013 at 4:42 Comment(3)
I don't know, but you may find this of interest: clang-developers.42468.n3.nabble.com/…Chordate
This answer may be helpful.Udometer
if you link against opencv, then use libstdc++. here's why #13038159Wooldridge
F
119

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

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.

More info here about the completeness of libc++ on various platforms.

Fixture answered 28/5, 2013 at 9:21 Comment(8)
Could you elaborate / provide links about the completeness status of libc++ on Linux? I don't quite understand why this would be platform-specific as libc++ is just a bunch of Standard Library headers. Or do you mean that one needs to build Clang wrt to LLVM runtime libraries that are not well supported on Linux?Cocytus
@TemplateRex, I don't know the current status, you can look on libcxx.llvm.org. I don't follow libc++ so you're asking the wrong person, but are you suggesting that "a bunch of Standard Library headers" will never have any platform-specific code?Fixture
Well since you can install Linux on pretty much the same Apple hardware that is running Mac OS X, I wonder where the platform dependency in C++ headers would come from? Maybe some wrappers around builtin CPU intrinsics or IO and exception handling stuff are system dependent, but my understanding was that such stuff is handled in librcxxrt type of binary layers. Aren't the Standard Library headers supposed to be more or less pluggable?Cocytus
I'm not talking about hardware. Again, I have no idea about libc++, but most C++ standard libraries are implemented over the OS's C library, and e.g. mapping from std::ctype_base::mask values to <ctype.h> constants is entirely platform-dependent. (CPU intrinsics are provided by the compiler, exception handling is done by a low-level ABI layer, but IO is typically done entirely in the C++ and C libraries, not low-level stuff).Fixture
Thanks Jonathan, great info. I didn't mean to bug you about libc++ in particular as I know you are in the other camp, but I just wondered where platform dependence pops up in a Standard Library. Thanks again for taking the time to explain that.Cocytus
@JonathanWakely There is one strong argument for using libc++. That is statically linking, which might not be an option given libstdc++'s license.Conflict
@abergmeier, that's a bogus argument, because (when used with GCC or other eligible compilation processes) libstdc++ doesn't impose any restrictions on code using it, whether linked dynamically or statically. It's not the LGPL. Please don't spread FUD. gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.license.whatFixture
@JonathanWakely Ah interesting.Conflict
P
36

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

  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.

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

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.

Pablopabon answered 5/1, 2014 at 18:38 Comment(2)
Clang is not a GCC replacement... Just another compiler.Angloindian
@IsaacPascual What Mario meant is clang officially has in its design goals to be a drop-in replacement for the prominent compiler on the platform you run it on (e.g. gcc when run on linux). Same for intel's compiler afaik. It's their way to get a broader adoption.Unlearned

© 2022 - 2024 — McMap. All rights reserved.