Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++17 std::variant header file (clang 6.0.0)

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?

like image 980
Marco Massenzio Avatar asked Aug 13 '17 06:08

Marco Massenzio


1 Answers

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.

like image 187
Marshall Clow Avatar answered Nov 01 '22 21:11

Marshall Clow