8

Update

I narrowed down the problem to (probably! it's not entirely clear, even reading all I could find about the topic) that installing stdlibc++-7-dev would provide me with suitable (i.e., C++17-compliant) STL headers and libraries.

This (also, apparently) comes bundled with Ubuntu 17.04 (artful?) but is not available for xenial (Ubuntu 16.04.3 LTS) which is what I'm using.

I have tried downloading the individual .deb packages and installing them, but it quickly becomes a maze of unresolved dependencies.

If anyone could point me to how to install libstdc++-7-dev on 16.04, I'd be most grateful.

Original question

I have just installed clang++ 6.0 in Ubuntu 16.04 via the package manager (following these instructions) and all seems well: /usr/bin/clang++-6.0 works just fine, and if I try to use something that only works in C++17 (non-type template arguments with auto, see here) it compiles and runs, once I set CMAKE_CXX_COMPILER=/usr/bin/clang++-6.0 -- while it fails when I don't.

So... clang 6.0 understands C++17 as advertised (doh!) but when I use:

#include <variant>

the file is not found where I would expect it to be:

$ ll /usr/include/clang/6.0.0/
total 0
lrwxrwxrwx 1 root root 45 Aug  6 21:32 include -> ../../../lib/llvm-6.0/lib/clang/6.0.0/include

or anywhere else I can think of.

Would anyone know (a) whether it's supposed to be there at all and (b) if so, where do I go find it?

Update

I have double-checked that I have the latest (I think) stdc++ library:

$ sudo apt-get install libstdc++-5-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libstdc++-5-dev is already the newest version (5.4.0-6ubuntu1~16.04.4).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

and same for libstdc++-6-dev; also, I have libc++-dev:

$ sudo apt-get install libc++-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libc++-dev is already the newest version (3.7.0-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Still, the variant.h* file is nowhere to be found. Anything else I should try?

Marco Massenzio
  • 2,822
  • 1
  • 25
  • 37
  • Try adding `-stdlib=libc++` to both the compiler and the linker. – KayEss Aug 13 '17 at 06:34
  • Just a quick question: Does Clang 4.0.0 support C++17 or is it only 6.0? This is the first time I'm hearing about 6.0 – Post Self Aug 13 '17 at 06:57
  • Some parts are supported, but still under the `c++1z` flag (I don't expect this to change until the standard is ratified). I think they've switched to 6 in development as they're getting ready to release 5. – KayEss Aug 13 '17 at 07:04
  • Clang is a compiler. The standard library is separate. – T.C. Aug 13 '17 at 07:41
  • @T.C. yes, I get that, my question was, how do I get a C++17-compatible STL? I thought it would come installed with the other packages, but clearly it wasn't. – Marco Massenzio Aug 14 '17 at 14:02
  • 1
    @kim366 just found this page: http://en.cppreference.com/w/cpp/compiler_support looks like clang-4 supports most features, but a couple only came out with 5. – Marco Massenzio Aug 14 '17 at 14:18
  • @Marco Okay. I just find it weird that there is no mention about Clang 6.0 (http://releases.llvm.org/download.html#4.0.1) – Post Self Aug 14 '17 at 14:19
  • 1
    Anyways, maybe try including ``. That's what I was doing with ``, before I updated my compiler – Post Self Aug 14 '17 at 14:21
  • Thanks, @kim366, that helped narrow it a bit: I found `/usr/include/c++/5/experimental/` which seems to be the bits supporting C++14 - still no `variant` header in that folder, but now I'm guessing it's a case of tracking down which package adds the header files for the STL to support C++17 – Marco Massenzio Aug 14 '17 at 14:32
  • @kim366 There is no such thing as ``. – T.C. Aug 14 '17 at 15:47
  • @T.C. It was worth a try.. – Post Self Aug 14 '17 at 17:13
  • You can update to gcc 7.1 and use libstdc++ through clang. – Post Self Aug 14 '17 at 17:14
  • Clang 5.0 is about to be released. (probably early September). 6.0 is the next release - probably March 2018. – Marshall Clow Aug 15 '17 at 05:03
  • @kim366 clang 6 is a dev branch [apt.llvm.org](http://apt.llvm.org/). I'm also confused about how to get c++17 headers. `string_view` is part of the standard now and `experimental/string_view` is from TS. – Alexandre A. Oct 12 '17 at 21:26

1 Answers1

3

Yes, clang 5.0 (or rather, the libc++ that will ship as part of clang 5) has the <variant> header. But you need to be sure that you have installed libc++.

And as @KayEss mentioned, you'll need to pass -std=c++17 (or the earlier version of the same flag -std=c++1z) because variant is a C++17-only feature.

Marshall Clow
  • 15,972
  • 2
  • 29
  • 45
  • 1
    Can you please elaborate on the "you need to be sure that you have installed libc++" part? I have installed clang++-6 package (and verified it works fine) along with other packages that were "suggested" by `apt-get`: however, when I looked into the `libstdc++` packages to install, I didn't see anything obvious to install. (and, yes, I already use the `--std=c++17` flag - but that would fail the compilation: it's the header file that's missing) – Marco Massenzio Aug 16 '17 at 20:55
  • 2
    When you install clang for (say) Ubuntu, it comes set up to use the already installed C++ standard library (libstdc++). This is helpful, because it means that you can "mix and match" object files compiled with gcc and clang. You need to install the `libcxx` package as well (example here: https://launchpad.net/ubuntu/+source/libc%2B%2B) and pass `-std=libc++` to clang. – Marshall Clow Aug 20 '17 at 04:19