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++?
-
1I don't know, but you may find this of interest: clang-developers.42468.n3.nabble.com/…– DarenWFeb 20, 2013 at 5:15
-
3This answer may be helpful.– Yantao XieFeb 20, 2013 at 9:18
-
2if you link against opencv, then use libstdc++. here's why stackoverflow.com/questions/13037659/…– MobileDevMar 7, 2013 at 5:14
2 Answers
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.
-
3Could 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? Nov 28, 2013 at 14:17
-
1@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? Nov 29, 2013 at 12:03
-
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? Nov 29, 2013 at 12:29
-
5I'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). Nov 29, 2013 at 12:32 -
3@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.what May 8, 2016 at 16:32
Major Linux distributions do not provide LLVM libc++, because:
- Unlike Apple and FreeBSD, the GPL+3 is not an issue, so no need to implement another stack here.
- Linux components have been developed around GNU libstd++ for ages. Some of them do not build on anything else.
- 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.
-
6
-
11@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. Aug 6, 2018 at 1:35