7

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?

5
  • What are the errors you are getting? Commented Jul 18, 2016 at 16:14
  • 1
    what system? on various linuses use the package manager query switch for whatever package manager you have (apt, yum, rpm ...). use man page or --help. Commented Jul 18, 2016 at 16:16
  • To use C++ you must use clang++ explicitly as command. Commented Jul 18, 2016 at 16:17
  • similar Centos clang issue is documented in stackoverflow.com/questions/25840088/… Commented Jul 18, 2016 at 16:32
  • 2
    Your error is elsewhere. If you were explicitly linking libc++ and it is not installed, the linker would tell you it cannot find libc++. Commented Jul 18, 2016 at 16:33

4 Answers 4

12

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

Sign up to request clarification or add additional context in comments.

2 Comments

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 <ciso646> 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.
Regarding the #include<ciso646>, I refer you to stackoverflow.com/questions/31657499/… (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)
7

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.

1 Comment

libc++ docs provide the details of what $(CXXFLAGS) and $(LDFLAGS) would be in a practical application.
5

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.

3 Comments

@okovko Check this out. It'll show you how to install software on your system. Try it. ask.fedoraproject.org/en/question/7863/… After that, we can delete this discussion since it is obsolete.
It would be nice to just install something fresh, but that is out of the question, as it is not my system.
@okovko Well, keep it handy just in case you can use it. Let's delete this discussion now that it's obsolete.
-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.

3 Comments

Well, it's about setting the compiler itself. cmake may call clang instead of clang++ internally, but I think it should have some variable to set the compiler (make itself has one)
I'd be surprised if the library were missing. Gcc should be able to link to that library if instructed.
...deleting comments and downvoting is downright impolite! Lol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.