2

Looking at clang-5.0 release notes it says that "C++ coroutines TS has landed", and suggests to check out this example to get started. I obviously can run the example online, so I decided to try on my Ubuntu Server 16.04 Xenial machine.

From a clean installation, I just tried

wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main"
sudo apt-get update
sudo apt-get install -y clang-5.0 libc++-dev

And went straight for

clang++-5.0 -Wall -Wextra -std=gnu++2a "-fcoroutines-ts" "-stdlib=libc++" -o test.out test.cpp 

(test.cpp being a copy-and-paste of the aforementioned example)

However, I just get

coroutines.cpp:2:10: fatal error: 'experimental/coroutine' file not found
#include <experimental/coroutine>

So I can imagine I am missing something, either to install or in the compilation flags. I tried to look online but I couldn't find anything useful.

What am I doing wrong?

underscore_d
  • 6,309
  • 3
  • 38
  • 64
Matteo Monti
  • 8,362
  • 19
  • 68
  • 114

1 Answers1

5

It seems that the repository you linked provides only the toolchain, but not the headers.

Installing libc++-dev you installed the package from the Ubuntu repositories, which do not include the header files in the experimental directory.

You can check this question to build libc++ by yourself and set up the toolchain appropriately.

Sergio Monteleone
  • 2,776
  • 9
  • 21
  • Thank you! I had actually seen that question, but it seems to refer to version 4 of `libc++`. I tried to replace all `4.0` with `5.0` but it produced a lot of errors.. – Matteo Monti Apr 17 '18 at 15:22
  • Yes, the linked answer requires a bit of thinkering... have you tried to install the **libstdc++-5-dev** package with apt-get install libstdc++-5-dev ? – Sergio Monteleone Apr 17 '18 at 15:27
  • 1
    I haven't! Are `libstdc++` and `libc++` the same thing? I am sorry, I tend to get confused about these issues. – Matteo Monti Apr 17 '18 at 15:32
  • No they aren't the same. libstdc++ is the package providing the **GNU Standard C++ library** while libc++ is the **LLVM** one. I suggested to install the libstdc++-5-dev to fix the errors you received trying to compile clang manually. – Sergio Monteleone Apr 17 '18 at 15:35
  • Apparently, `libstdc++-5-dev` was already installed in my system. I even tried changing `-stdlib=libc++` to `-stdlib=stdlibc++` but no dice, I get the same error message. I tried to `find` any file called `coroutine` in the system and there is none. – Matteo Monti Apr 17 '18 at 15:40
  • 2
    You can't mix the GNU standard library with LLVM compiler. There's no file named coroutine because the libc++ package you have doesn't provide it. I'm afraid, the only viable solution is to recompile libc++ by yourself. – Sergio Monteleone Apr 17 '18 at 15:49