0

I installed llvm for clang, because I wanted to use clang for code::blocks as compiler, since I need compiler that supports c++20, so I installed llvm, the bin was added in environmental variables, even the code::blocks detected llvm as compiler, however I get error when i want to compile my code:

-------------- Build file: "no target" in "no project" (compiler: unknown)---------------
clang++.exe -c C:\Users\Temirlan\labs\lab4\rpn.cpp -o C:\Users\Temirlan\labs\lab4\rpn.o
clang++.exe -o C:\Users\Temirlan\labs\lab4\rpn.exe C:\Users\Temirlan\labs\lab4\rpn.o
C:\Users\Temirlan\labs\lab4\rpn.cpp:180:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
1 error generated.

Do you know what is the problem or maybe the picture will help? photo of compiler executables in code::blocks

I got error of "fatal error: 'iostream' file not found"

JaMiT
  • 14,422
  • 4
  • 15
  • 31
  • Can you show a [mre] of code that produces this error? – Drew Dormann Feb 11 '23 at 18:00
  • just a simple default code to check: #include using namespace std; int main(){ int x; cin>>x; cout<<"it is working"; return 0; } – Temirlan Kaiyrbay Feb 11 '23 at 18:05
  • @TemirlanKaiyrbay If you want to go truly minimal, just `#include ` should be enough to reproduce the error (nothing needed after the `#include` line since compilation stops at that line). – JaMiT Feb 11 '23 at 18:22
  • The error message you posted is from the "build messages" tab? If you switch to the "build log" tab, do you see the command that was used to compile your code? The compile command might be useful information to copy into your question. – JaMiT Feb 11 '23 at 18:27
  • @JaMiT this one is from build log: "-------------- Build file: "no target" in "no project" (compiler: unknown)--------------- clang++.exe -c C:\Users\Temirlan\labs\lab4\rpn.cpp -o C:\Users\Temirlan\labs\lab4\rpn.o clang++.exe -o C:\Users\Temirlan\labs\lab4\rpn.exe C:\Users\Temirlan\labs\lab4\rpn.o C:\Users\Temirlan\labs\lab4\rpn.cpp:180:10: fatal error: 'iostream' file not found #include ^~~~~~~~~~ 1 error generated. Process terminated with status 1 (0 minute(s), 0 second(s)) 1 error(s), 0 warning(s) (0 minute(s), 0 second(s))" – Temirlan Kaiyrbay Feb 11 '23 at 19:58
  • @TemirlanKaiyrbay That is a more useful error message. I've copied it into your question, but I had to guess at the formatting a bit. Please double-check that I got the spacing and line breaks correct. – JaMiT Feb 11 '23 at 20:40

1 Answers1

2

All modern compilers support C++20 (to slightly varying extent): both Clang, GCC, and MSVC. So this shouldn't affect your choice (but I do think that Clang is the best option).

Clang can be set up in different ways: (in order of personal preference)

  • With GCC's standard C++ library, libstdc++. Install MSYS2, then use it to install both Clang and GCC: pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-clang. Then use C:/msys64/ucrt64/bin/clang++.exe as the compiler. (There's also MINGW64 variant instead of UCRT64, read about the difference here).

  • With its own standard C++ library, libc++. Install MSYS2, then use it to install libc++-flavored Clang: pacman -S mingw-w64-clang-x86_64-clang. Then use C:/msys64/clang64/bin/clang++.exe as the compiler.

  • With MSVC's standard C++ library, aka MSVC STL. Install the official Clang build, and install Visual Studio.

Note that the first two options don't involve downloading the official Clang build. The official build wants the MSVC STL by default, which you don't have, since you didn't install VS. (And if you do install it, you might as well use it instead of CodeBlocks.)

The official Clang build can be made to work with other standard libraries, but they need to be installed separately, and you need to persuade it with some compiler flags. It's easier to install the MSYS2's version, which already uses the correct flags by default.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
  • Doesnt my installation work normal? I installed llvm, attached "C:\LLVM\bin" to system variables, auto-detected compiler in code::blocks, which showed "C:\LLVM", but still it shows error, maybe I missed some of the parts? – Temirlan Kaiyrbay Feb 11 '23 at 18:18
  • @TemirlanKaiyrbay As I said (maybe it wasn't too clear), it tries to find Visual Studio installation and doesn't find one. You either install a different version of Clang that doesn't need one, or install VS (but then why use CB at all). – HolyBlackCat Feb 11 '23 at 19:19
  • So, I did as you said, but when i compile a code, and it give me this error: "error: no type named 'string_view' in namespace 'std'", and when I chekced in flags, Idid not see c++20 flag, so I guess this clang++ does not support c++20, do you know what I can do? – Temirlan Kaiyrbay Feb 11 '23 at 20:10
  • For that last error did you `#include `? Also `string_view` was introduced in c++17 – drescherjm Feb 11 '23 at 22:29
  • @TemirlanKaiyrbay "when I chekced in flags" You mean CodeBlocks doesn't have a checkbox for it? It doesn't mean anything, they have a fixed list of checkboxes. Your must add `-std=c++20` flag manually to "other compiler settings". – HolyBlackCat Feb 12 '23 at 03:50
  • As I understood you, I added new flag in "compiler flags->general", named it as "have", in compiler flags wrote "-std=c++20". It's okay, but another point is that, now my code runs and shows output, but in build messages I see this line "||=== Build file: "no target" in "no project" (compiler: unknown) ===|". I know that code runs, but I guess that "unknown compiler" is a problem for larger projects? My guess is that I chose wrong choice in "selected compiler", now I have "GNU GCC compiler", while using C:\msys64\ucrt64\bin for g++, you know how to fix it? – Temirlan Kaiyrbay Feb 12 '23 at 08:02
  • Also, I changed my mind about using clang, the main thing for me that compiler supports c++20 – Temirlan Kaiyrbay Feb 12 '23 at 08:02
  • @TemirlanKaiyrbay If this is just a message, I would ignore it. Looks harmless to me. As for what compiler to use, Clang has several advantages. It works *a lot* faster than GCC on Windows, and is known to have good standard conformance (a lot better than MSVC, and perhaps slightly better than GCC). Also IDEs have plugins for Clang-based code completion, that will never disagree with your compiler (see Clangd, might be a good idea to install it for CB). – HolyBlackCat Feb 12 '23 at 10:43