How to Use Clang++ with -Std=C++11 -Weverything -Werror

Does clang already support C++11?

Yes but not everything. Check out this status page; it's updated very frequently. It's the current source code (work in progress) state, not the last release state, so check the version in the table to be sure it corresponds to what you have.

For standard library features, checks the links at the end of the page, depending on which context you are in.

Also, the Apache wiki includes this table summarizing C++11 features and their support in popular compilers.

How to install Clang 11 on Debian

I found the solution after some searching. Here is what I did to make it work:

  1. Add the following lines to your /etc/apt/sources.list:
deb http://apt.llvm.org/buster/ llvm-toolchain-buster main 
deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster main
deb http://apt.llvm.org/buster/ llvm-toolchain-buster-10 main
deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-10 main
deb http://apt.llvm.org/buster/ llvm-toolchain-buster-11 main
deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-11 main

  1. Add signatures for these repos (otherwise apt-get update will complain in the next step)
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -

  1. Run apt-get update to add these new repos to the apt-get:
sudo apt-get update

  1. Install clang-11:
sudo apt-get install clang-11

  1. Make sure now "clang-11" is used by the compiler and not the older "clang":
export CMAKE_C_COMPILER=clang-11
export CMAKE_CXX_COMPILER=clang++-11

  1. Compile your project.
  2. Enjoy!

For documentation: https://apt.llvm.org/

Clang or GCC compiler for c++ 11 compatibility programming on Windows?

Notice that compiler != IDE.

VC++ is one of the most populars on Windows and depending on its version it has a good support for C++11 features. Check the list on the msdn blog to find out if there's everything you need.

Gcc is also ported to Windows and you can install MinGW to use it (4.8.1.4 at the moment of writing this). It is pretty complete on C++11.

Clang is also available for the Windows platform and it is also complete on C++11 support (plus it has good diagnostic messages), but notice that you will have to use another linker since clang doesn't ship with one (although there is an ongoing effort to write it: http://lld.llvm.org/)

All the compilers I cited above are pretty stable but, based on my experience, if you're looking for latest and greatest C++11/14/17 features, you might just want to go for gcc or clang (VC++ is slower in adding support for newest features and the compiler is undergoing a huge update to modernize). Just keep in mind that these are compilers and not just IDEs, an IDE is a front-end supporting program that uses a compiler undercover to compile files.

Do I have to build clang-11 from source on Ubuntu 18.04 to have OpenMP GPU target offload?

The Debian/Ubuntue packages for LLVM do not come with OpenMP offload support for GPUs [0] (at least until LLVM 11) . Packaging this is a bit tricky but we are working on it. One of the tricky parts, for now, is that for reasonable performance it requires a two stage build and you need(ed) to specify what GPU architectures you are targeting. The latter requirement is partially gone in LLVM now as we look at the build machine configuration and make a reasonable guess but was still there in the LLVM 11 release (IIRC). We are working on eliminating the two stage requirement as well, among other things.

While pretty new and mostly empty, these things will eventually be described here:
http://openmp.llvm.org/docs

Also, if you have questions or concerns, don't hesitate to send an email to openmp-dev@lists.llvm.org :)

Lastly, at first glance the script by @ouankou looks pretty good, except that I usually recommend the latest top-of-trunk over a release. It can be unstable but, TBH, for OpenMP offload support it is probably not any less stable than a release.

[0] CMake excerpt: https://paste.debian.net/1171752/ (thanks Sylvestre!)



Related Topics



Leave a reply



Submit