cppcoro icon indicating copy to clipboard operation
cppcoro copied to clipboard

Clang/GCC incompatiblity

Open Garcia6l20 opened this issue 4 years ago • 5 comments

There are few problems with clang.

First, It is not able to find GCC headers, it is caused by -fcoroutines-ts and -fcoroutines does not define the same preprocessor definition, It can be workarounded with -D__cpp_impl_coroutine=1 (what -fcoroutines does).

And now, clang complains that a coroutine cannot be used without <experimental/coroutine> inclusion what is breaking with GCC.

eg.:

~/cppcoro/test/async_latch_tests.cpp:59:4: error: std::experimental::coroutine_traits type was not found; include <experimental/coroutine> before defining a coroutine
                        co_await latch;
                        ^

Currently the only way to use with clang is to use libc++ (tested with clang-12 on Arch):

cmake -DCMAKE_CXX_FLAGS="-stdlib=libc++" <path_to_sources>

Garcia6l20 avatar Oct 12 '20 06:10 Garcia6l20

On ubuntu, executables must be explicitly linked with -lc++:

cmake -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_EXE_LINKER_FLAGS="-lc++" <path_to_sources>

Garcia6l20 avatar Oct 12 '20 09:10 Garcia6l20

Is this now solved with the latest changes in the integrate_all branch?

andreasbuhr avatar Oct 21 '20 19:10 andreasbuhr

No, it is not. Clang will only compile with libc++, but it should also work with libstdc++. This won't change until clang updates it's coroutine header to non-experimental path, or even accept it.

Garcia6l20 avatar Oct 22 '20 06:10 Garcia6l20

I guess this is solved in the master branch of andreasbuhr/cppcoro? I see that more documentation is required.

andreasbuhr avatar Dec 08 '20 08:12 andreasbuhr

The answer is simple can you build it with clang without --stdlib=libc++ ?

Garcia6l20 avatar Dec 09 '20 17:12 Garcia6l20