Because of a known bug (https://github.com/msys2/MINGW-packages/issues/11495) that started appearing with MSYS2/CLANG64/Clang 14.0.0, Compiling any file failed because gcc is on the Path.
They should be two separate configurations, Why does "CodeBlocks" add "GNU GCC Compiler" PATH in the first place.
Reproducer:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(test CXX)
add_custom_target(pre_compile ${CMAKE_COMMAND} -E environment)
add_executable(main main.cpp)
add_dependencies(main pre_compile)
main.cpp:
#include <iostream>
int main () {
std::cout << "Hello World!" << std::endl;
}
$ mkdir build && cd build
$ cmake .. -G"CodeBlocks - Ninja"
Click Project File -> Build:
-------------- Build: main in test (compiler: LLVM Clang Compiler)---------------
Checking if target is up-to-date: mingw32-make.exe -q -f Makefile main
Running command: D:/Programs/msys64/clang64/bin/ninja.exe -v main
[0/1] D:\Programs\msys64\clang64\bin\cmake.exe --regenerate-during-build -SD:\dev\Bugs\cmake_code -BD:\dev\Bugs\cmake_code\build
-- Configuring done
-- Generating done
-- Build files have been written to: D:/dev/Bugs/cmake_code/build
[1/3] cmd.exe /C "cd /D D:\dev\Bugs\cmake_code\build && D:\Programs\msys64\clang64\bin\cmake.exe -E environment"
...
Path=D:\Programs\msys64\clang64\bin;D:\Programs\msys64\clang64;D:\Programs\msys64\ucrt64\bin;D:\Programs\msys64\ucrt64;D:\Programs\msys64\usr\bin;C:\Program Files\Python310\Scripts\;C:\Program Files\Python310\;...
...
[2/3] D:\Programs\msys64\clang64\bin\c++.exe -MD -MT CMakeFiles/main.dir/main.cpp.obj -MF CMakeFiles\main.dir\main.cpp.obj.d -o CMakeFiles/main.dir/main.cpp.obj -c D:/dev/Bugs/cmake_code/main.cpp
FAILED: CMakeFiles/main.dir/main.cpp.obj
D:\Programs\msys64\clang64\bin\c++.exe -MD -MT CMakeFiles/main.dir/main.cpp.obj -MF CMakeFiles\main.dir\main.cpp.obj.d -o CMakeFiles/main.dir/main.cpp.obj -c D:/dev/Bugs/cmake_code/main.cpp
D:/dev/Bugs/cmake_code/main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
PATH outside of CodeBlocks:
$ echo %PATH%
C:\Program Files\Python310\Scripts\;C:\Program Files\Python310\;...
A workaround is setting "LLVM Clang Compiler" As default compiler and then close and open CodeBlocks.
This workaround doesn't work if the "Clang" project is opened after a "GCC" project.
Also, Why the toolchain Path was added twice?
This is a cmake generated project?
What is the active compiler of the project?
can you share a example project file?
Yes
LLVM Clang compiler
In my case the generated Project file test.cbp:
First the problem has nothing to do with C::B.
The issue is that the C++ support files for clang64 have not been installed and therefore when trying to compile using the clang64 shell any C++ file that uses any C++ include file (not C) will fail as shown in the original post (fatal error: 'iostream' file not found).
To fix this from memory you need to to install one or both of the following (I had the same issue earlier this year):
mingw-w64-clang-x86_64-libc++
mingw-w64-clang-x86_64-libc++abi
Even after installing one or both of the files above you will then hit other issues.
With MSYS2 you are advised to install for each of the compilers the applicable toolchain group package.
In the case of Clang64 the toolchain to install is:
https://packages.msys2.org/group/mingw-w64-clang-x86_64-toolchain
As such this ticket can be closed as it's a MSYS2 configuration issue.
No, you are completely wrong.
I have all required clang packages installed.
The project built successfully outside of CodeBlocks in CLANG64 shell.
The issue is that whenever Clang detect gcc in PATH things work differently. see https://github.com/msys2/MINGW-packages/issues/11495
Installing toolchain is just a workaround.
You may better show some respect when commenting on issues by reading what people wrote, before writing anything.
Please re-read the my report to better understand the issue.
CodeBlocks shouldn't prepend/append any PATH not related to the current toolchain.
Respect goes both ways and in my post I said "I had the same issue earlier this year" and I fixed it by installing the C++ headers for clang from memory. I followed your original post instructions and they worked for me, so yes I did read what you wrote.
If you followed the github threads then you would have read
https://github.com/msys2/MINGW-packages/issues/10762 posts and spotted that the fix in that ticket was to install the gcc-compat package that is included in the toolchain group package.
If it is working outside C::B then have you tried the C::B nightly 12829 as it works for me without any issues. So from my perspective the issue is with MSSY2 and not C::B.
Which version of C::B are you using?
Which version of Clang are you using?
Are you using the latest MSYS2 packages?
Do you have any of the following MSYS2 packages installed?
* mingw-w64-clang-x86_64-libc++ * mingw-w64-clang-x86_64-libc++abi * mingw-w64-clang-x86_64-toolchain * mingw-w64-clang-x86_64-gcc-compat
What is your default compiler set to?
I could build my project on CLANG64 shell without installing gcc-compat and toolchain.
Why does CB fail to? because simply it prepends non-related PATH to the current environment. Do you understand?
I don't want to apply a workaround, I want to fix the main issue about CB behavior.
I hope you understand.
CB 12829 works for you without any issue because you have gcc-compat installed.
Uninstall gcc-compat and see!
Second and last attempt:
Which version of C::B are you using?
Which version of Clang are you using?
Are you using the latest MSYS2 packages?
Do you have any of the following MSYS2 packages installed? * mingw-w64-clang-x86_64-libc++ * mingw-w64-clang-x86_64-libc++abi * mingw-w64-clang-x86_64-toolchain * mingw-w64-clang-x86_64-gcc-compat
What is your default compiler set to?
svn 12829
14.0.4
Of course.
yes
no
It looks like you didn't try to even read my whole report. see above to know.
Read my first posts.
Last edit: Mehdi Chinoune 2022-06-09
Good luck.
related Ticket: #1351