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?
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.
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.
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++.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With