6

I am building something from source. My system's gcc and stdlibc++ are too old, but there is a clang build I can use. By default, clang uses stdlibc++, but libc++ may optionally be installed for clang to use.

What is the best way to check if libc++ is installed with clang?

okovko
  • 1,851
  • 14
  • 27

4 Answers4

8

Slightly better answer than @n.n:

printf "#include <ciso646>\nint main () {}" | clang -E -stdlib=libc++ -x c++ -dM - | grep _LIBCPP_VERSION

If that prints something like: #define _LIBCPP_VERSION 3700, then you've got libc++.

Marshall Clow
  • 15,972
  • 2
  • 29
  • 45
  • This one liner is preferable; at least on my system, n.m.'s approach could not be altered without retyping the entire command. Could you explain what some of the symbols are, like and -E -dM? Also I would add that on a non-trivial system with many clang build versions, you can replace "clang" with path/to/particular-clang-build/bin/clang. – okovko Jul 18 '16 at 21:00
  • 1
    Regarding the `#include`, I refer you to http://stackoverflow.com/questions/31657499/how-to-detect-stdlib-libc-in-the-preprocessor (which amusingly enough is in response to another answer I gave), and `clang++ -E -dM` tells clang not to compile the source, but just to preprocess it (the `-E`) and then to print out all the things that are defined (the `-dM`) – Marshall Clow Jul 18 '16 at 22:44
6

The most straightforward way to check if libc++ is installed is to use it on a trivial program:

 clang++ -xc++ -stdlib=libc++ - <<EOF
 int main(){}
 EOF

If this fails, you don't have libc++.

In a real-world application, add user-supplied compiler and linker options:

 clang++ $(CXXFLAGS) $(LDFLAGS) -xc++ -stdlib=libc++ - <<EOF

so that the user has a chance to specify that libc++ is installed in a non-standard place.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • [libc++ docs](http://libcxx.llvm.org/docs/UsingLibcxx.html) provide the details of what $(CXXFLAGS) and $(LDFLAGS) would be in a practical application. – okovko Jul 18 '16 at 18:54
4

Here's how to check if a library is installed:

Type ldconfig -p | grep libc++ into the terminal. It does not matter what system you are using. If libc++ is not installed, the terminal will not say anything. If it is installed, it will display the available versions.

  • @okovko Check this out. It'll show you how to install software on your system. Try it. https://ask.fedoraproject.org/en/question/7863/how-do-i-search-for-and-install-software-packages-in-fedora/ After that, we can delete this discussion since it is obsolete. –  Jul 18 '16 at 17:23
  • It would be nice to just install something fresh, but that is out of the question, as it is not my system. – okovko Jul 18 '16 at 17:30
  • @okovko Well, keep it handy just in case you can use it. Let's delete this discussion now that it's obsolete. –  Jul 18 '16 at 17:40
-1

It's possible you get a confusion that both gcc and clang do. To compile code as C++, you have to use g++ instead of gcc, respectively clang++ instead of clang.

I doubt the libc++ libraries themselves are missing, since it's almost certain some program depends on them.

Paul Stelian
  • 1,381
  • 9
  • 27