Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 906
okovko Avatar asked Jul 18 '16 16:07

okovko


People also ask

How do I check my libc?

The process for checking your installed version of libc will be the same regardless of your Linux distro. Simply use the ldd command as seen below. $ ldd --version ldd (Ubuntu GLIBC 2.35-0ubuntu3) 2.35 ... As you can see from the first line of the output and in the previous screenshot, we have version 2.35 installed.

How do I know if a library is installed in Linux?

In terms of commands, we may use the ldd command to find out missing dependencies. Also, we can use the ldconfig command with the -p option to check if a shared library is installed. Finally, we should check the standard library paths like /usr/lib and /usr/local/lib as well as extra paths listed in the /etc/ld.


2 Answers

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

like image 173
Marshall Clow Avatar answered Sep 20 '22 08:09

Marshall Clow


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.

like image 34
n. 1.8e9-where's-my-share m. Avatar answered Sep 19 '22 08:09

n. 1.8e9-where's-my-share m.