Menu

#1263 CodeBlocks add "GNU GCC Compiler" Path to "LLVM Clang Compiler" Path.

Undefined
open
nobody
None
Bug_Report
2023-01-05
2022-04-30
No

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\;...

Discussion

  • Mehdi Chinoune

    Mehdi Chinoune - 2022-05-01

    A workaround is setting "LLVM Clang Compiler" As default compiler and then close and open CodeBlocks.

     
    • Mehdi Chinoune

      Mehdi Chinoune - 2022-05-01

      This workaround doesn't work if the "Clang" project is opened after a "GCC" project.

       
  • Mehdi Chinoune

    Mehdi Chinoune - 2022-05-01

    Also, Why the toolchain Path was added twice?

     
  • bluehazzard

    bluehazzard - 2022-05-02

    This is a cmake generated project?
    What is the active compiler of the project?
    can you share a example project file?

     
    • Mehdi Chinoune

      Mehdi Chinoune - 2022-05-02

      This is a cmake generated project?

      Yes

      What is the active compiler of the project?

      LLVM Clang compiler

      can you share a example project file?

      • Install MSYS2 (https://www.msys2.org/)
      • Open CLANG64 shell/environment and install required tools
      $ pacman -S mingw-w64-clang-x86_64-clang mingw-w64-clang-x86_64-cmake mingw-w64-clang-x86_64-ninja
      
      • Generate CodeBlocks project as explained in first post.

      In my case the generated Project file test.cbp:

      <?xml version="1.0" encoding="UTF-8"?>
      <CodeBlocks_project_file>
          <FileVersion major="1" minor="6"/>
          <Project>
              <Option title="test"/>
              <Option makefile_is_custom="1"/>
              <Option compiler="clang"/>
              <Option virtualFolders="CMake Files\;"/>
              <Build>
                  <Target title="all">
                      <Option working_dir="D:/dev/Bugs/cmake_code/build"/>
                      <Option type="4"/>
                      <MakeCommands>
                          <Build command="D:/Programs/msys64/clang64/bin/ninja.exe -v all"/>
                          <CompileFile command="D:/Programs/msys64/clang64/bin/ninja.exe -v &quot;$file&quot;"/>
                          <Clean command="D:/Programs/msys64/clang64/bin/ninja.exe -v clean"/>
                          <DistClean command="D:/Programs/msys64/clang64/bin/ninja.exe -v clean"/>
                      </MakeCommands>
                  </Target>
                  <Target title="pre_compile">
                      <Option working_dir="D:/dev/Bugs/cmake_code/build"/>
                      <Option type="4"/>
                      <MakeCommands>
                          <Build command="D:/Programs/msys64/clang64/bin/ninja.exe -v pre_compile"/>
                          <CompileFile command="D:/Programs/msys64/clang64/bin/ninja.exe -v &quot;$file&quot;"/>
                          <Clean command="D:/Programs/msys64/clang64/bin/ninja.exe -v clean"/>
                          <DistClean command="D:/Programs/msys64/clang64/bin/ninja.exe -v clean"/>
                      </MakeCommands>
                  </Target>
                  <Target title="main">
                      <Option output="D:/dev/Bugs/cmake_code/build/main.exe" prefix_auto="0" extension_auto="0"/>
                      <Option working_dir="D:/dev/Bugs/cmake_code/build"/>
                      <Option object_output="./"/>
                      <Option type="1"/>
                      <Option compiler="clang"/>
                      <Compiler>
                          <Add directory="D:/Programs/msys64/clang64/include/c++/v1"/>
                          <Add directory="D:/Programs/msys64/clang64/lib/clang/14.0.0/include"/>
                          <Add directory="D:/Programs/msys64/clang64/include"/>
                      </Compiler>
                      <MakeCommands>
                          <Build command="D:/Programs/msys64/clang64/bin/ninja.exe -v main"/>
                          <CompileFile command="D:/Programs/msys64/clang64/bin/ninja.exe -v &quot;$file&quot;"/>
                          <Clean command="D:/Programs/msys64/clang64/bin/ninja.exe -v clean"/>
                          <DistClean command="D:/Programs/msys64/clang64/bin/ninja.exe -v clean"/>
                      </MakeCommands>
                  </Target>
                  <Target title="main/fast">
                      <Option output="D:/dev/Bugs/cmake_code/build/main.exe" prefix_auto="0" extension_auto="0"/>
                      <Option working_dir="D:/dev/Bugs/cmake_code/build"/>
                      <Option object_output="./"/>
                      <Option type="1"/>
                      <Option compiler="clang"/>
                      <Compiler>
                          <Add directory="D:/Programs/msys64/clang64/include/c++/v1"/>
                          <Add directory="D:/Programs/msys64/clang64/lib/clang/14.0.0/include"/>
                          <Add directory="D:/Programs/msys64/clang64/include"/>
                      </Compiler>
                      <MakeCommands>
                          <Build command="D:/Programs/msys64/clang64/bin/ninja.exe -v main/fast"/>
                          <CompileFile command="D:/Programs/msys64/clang64/bin/ninja.exe -v &quot;$file&quot;"/>
                          <Clean command="D:/Programs/msys64/clang64/bin/ninja.exe -v clean"/>
                          <DistClean command="D:/Programs/msys64/clang64/bin/ninja.exe -v clean"/>
                      </MakeCommands>
                  </Target>
                  <Target title="edit_cache">
                      <Option working_dir="D:/dev/Bugs/cmake_code/build"/>
                      <Option type="4"/>
                      <MakeCommands>
                          <Build command="D:/Programs/msys64/clang64/bin/ninja.exe -v edit_cache"/>
                          <CompileFile command="D:/Programs/msys64/clang64/bin/ninja.exe -v &quot;$file&quot;"/>
                          <Clean command="D:/Programs/msys64/clang64/bin/ninja.exe -v clean"/>
                          <DistClean command="D:/Programs/msys64/clang64/bin/ninja.exe -v clean"/>
                      </MakeCommands>
                  </Target>
                  <Target title="rebuild_cache">
                      <Option working_dir="D:/dev/Bugs/cmake_code/build"/>
                      <Option type="4"/>
                      <MakeCommands>
                          <Build command="D:/Programs/msys64/clang64/bin/ninja.exe -v rebuild_cache"/>
                          <CompileFile command="D:/Programs/msys64/clang64/bin/ninja.exe -v &quot;$file&quot;"/>
                          <Clean command="D:/Programs/msys64/clang64/bin/ninja.exe -v clean"/>
                          <DistClean command="D:/Programs/msys64/clang64/bin/ninja.exe -v clean"/>
                      </MakeCommands>
                  </Target>
              </Build>
              <Unit filename="D:/dev/Bugs/cmake_code/main.cpp">
                  <Option target="main"/>
              </Unit>
              <Unit filename="D:/dev/Bugs/cmake_code/CMakeLists.txt">
                  <Option virtualFolder="CMake Files\"/>
              </Unit>
          </Project>
      </CodeBlocks_project_file>
      
       
  • Andrew Cottrell

    Andrew Cottrell - 2022-06-09

    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.

     
    • Mehdi Chinoune

      Mehdi Chinoune - 2022-06-09

      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.

       
      • Andrew Cottrell

        Andrew Cottrell - 2022-06-09

        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?

         
        • Mehdi Chinoune

          Mehdi Chinoune - 2022-06-09

          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!

           
          • Andrew Cottrell

            Andrew Cottrell - 2022-06-09

            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?

             
            • Mehdi Chinoune

              Mehdi Chinoune - 2022-06-09

              Second and last attempt:
              Which version of C::B are you using?

              svn 12829

              Which version of Clang are you using?

              14.0.4

              Are you using the latest MSYS2 packages?

              Of course.

              Do you have any of the following MSYS2 packages installed?
              mingw-w64-clang-x86_64-libc++

              yes

              mingw-w64-clang-x86_64-libc++abi
              mingw-w64-clang-x86_64-toolchain
              mingw-w64-clang-x86_64-gcc-compat

              no

              What is your default compiler set to?

              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
              • Andrew Cottrell

                Andrew Cottrell - 2022-06-09

                Good luck.

                 
  • bluehazzard

    bluehazzard - 2023-01-05

    related Ticket: #1351

     

Log in to post a comment.