bug#43023: clang++ in a {clang-toolchain + gcc-toolchain} environment

2020-10-22 Thread Ludovic Courtès
Hi Emmanuel,

Emmanuel Agullo  skribis:

> A typical "hello world" C++ fails in an environment with both
> `gcc-toolchain' and `clang-toolchain', apperently due to the setup of
> the `CPLUS_INCLUDE_PATH' environment variable (used because of the
> `#include ' instruction), when compiling with `clang++'.

Did you want to have both toolchains in the environment, or was the goal
to use Clang, but GCC just happened to be already there (being the
default toolchain)?

In the latter case, the new ‘--with-c-toolchain’ option may help: it
allows you to select ‘clang-toolchain’ instead of the default GCC tool
chain.  Note “instead of” rather than “in addition to”, which means that
there’s only one tool chain in the environment, so no risk of
interference.

  
https://guix.gnu.org/manual/devel/en/html_node/Package-Transformation-Options.html

Now, if you really want the two toolchains in the same environment,
we’ll have to investigate, though I’m not sure it’s even fixable as it
breaks assumptions behind uses of #include_next in libstdc++ and
elsewhere.

Thanks,
Ludo’.





bug#43023: clang++ in a {clang-toolchain + gcc-toolchain} environment

2020-08-24 Thread Emmanuel Agullo
Hello, 

A typical "hello world" C++ fails in an environment with both 
`gcc-toolchain' and `clang-toolchain', apperently due to the setup of 
the `CPLUS_INCLUDE_PATH' environment variable (used because of the 
`#include ' instruction), when compiling with `clang++'. 

I do not know if this is a bug or the expected behaviour. Obviously one 
is not likely to explicitly load an environment with both `gcc-toolchain' 
and `clang-toolchain' but migth do so implictly (and possibly not being 
aware of it) for instance having `gcc-toolchain' globally installed and 
at some point loading `clang-toolchain' in an environment. 

Note that it is not critical at all in practice in my case, and I do 
not know whether it it is desirable to fix it in some way, or, maybe 
mention the incompatibility somewhere 
( ?) if not 
already done so – in which case I am sorry for the noise. 

Please find below: 
1. a simplified C++ "hello world" hello.cpp program 
2. an expected g++ behaviour in a `gcc-toolchain' environment 
3. an expected clang++ behaviour in a `clang-toolchain' environment 
4. an environment with both `gcc-toolchain' & `clang-toolchain' 
- 4.1. with an expected behaviour using `g++' 
- 4.2. with an (expected or not?) error using `clang++' 
- 4.3. a (non desirable) fix of the `CPLUS_INCLUDE_PATH' (removing 
`/gnu/store/…/include/c++') 
5. the employed channels if it may help 

Thanks much for the continous development and support, and once 
again sorry for the possible noise if this is a known expected 
behaviour. 

With best regards, 

Emmanuel 


1 simplified (no newline) C++ "hello world" hello.cpp program 
═ 

┌ 
│ #include  
│ 
│ int main() { 
│ std::cout << "Hello World!"; 
│ return 0; 
│ } 
└ 


2 `gcc-toolchain' environment 
═ 

┌ 
│ guix environment -C --ad-hoc gcc-toolchain coreutils grep 
│ env | grep CPLUS_INCLUDE_PATH 
│ g++ hello.cpp 
│ ./a.out 
└ 


 
CPLUS_INCLUDE_PATH=/gnu/store/gsylxn8q06w6y7622nw159f3q1vvcx2i-profile/include/c++:/gnu/store/gsylxn8q06w6y7622nw159f3q1vvcx2i-profile/include
 
Hello World! 

 


3 `clang-toolchain' environment 
═══ 

┌ 
│ guix environment -C --ad-hoc clang-toolchain coreutils grep 
│ env | grep CPLUS_INCLUDE_PATH 
│ clang++ hello.cpp 
│ ./a.out 
└ 


 
CPLUS_INCLUDE_PATH=/gnu/store/8qlafmilvc0g1yv8lmilpjmps3p4nrmq-profile/include 
Hello World! 

 


4 environment with both `gcc-toolchain' & `clang-toolchain' 
═══ 

4.1 compilation with `g++' 
── 

`g++' in an environment with both gcc and clang toolchains is fine: 
┌ 
│ guix environment -C --ad-hoc gcc-toolchain clang-toolchain coreutils grep 
│ env | grep CPLUS_INCLUDE_PATH 
│ g++ hello.cpp 
│ ./a.out 
└ 


 
CPLUS_INCLUDE_PATH=/gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++:/gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include
 
Hello World! 

 


4.2 compilation with `clang++' (FAIL) 
─ 

But `clang++' in the same environment (with both gcc and clang 
toolchains) breaks, raising the following error: 
┌ 
│ guix environment -C --ad-hoc gcc-toolchain clang-toolchain coreutils grep 
│ clang++ hello.cpp 
└ 

Error obtained during the `clang++ hello.cpp' step: 
┌ 
│ In file included from hello.cpp:1: 
│ In file included from 
/gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/iostream:39: 
│ In file included from 
/gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/ostream:38: 
│ In file included from 
/gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/ios:39: 
│ 
/gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/exception:105:3:
 error: unknown type name '_GLIBCXX17_DEPRECATED' 
│ _GLIBCXX17_DEPRECATED 
│ ^ 
│ In file included from hello.cpp:1: 
│ In file included from 
/gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/iostream:39: 
│ In file included from 
/gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/ostream:38: 
│