okovko
okovko

Reputation: 1911

How to check if libc++ is installed?

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?

Upvotes: 7

Views: 9405

Answers (4)

Marshall Clow
Marshall Clow

Reputation: 16690

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

Upvotes: 10

n. m. could be an AI
n. m. could be an AI

Reputation: 120059

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.

Upvotes: 7

user6054931
user6054931

Reputation:

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.

Upvotes: 5

Paul Stelian
Paul Stelian

Reputation: 1379

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.

Upvotes: -1

Related Questions