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"

6
  • Can you show a minimal reproducible example of code that produces this error? Commented Feb 11, 2023 at 18:00
  • just a simple default code to check: #include <iostream> using namespace std; int main(){ int x; cin>>x; cout<<"it is working"; return 0; } Commented Feb 11, 2023 at 18:05
  • @TemirlanKaiyrbay If you want to go truly minimal, just #include <iostream> should be enough to reproduce the error (nothing needed after the #include line since compilation stops at that line). Commented Feb 11, 2023 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. Commented Feb 11, 2023 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 <iostream> ^~~~~~~~~~ 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))" Commented Feb 11, 2023 at 19:58

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

8 Comments

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?
@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).
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?
For that last error did you #include <string_view>? Also string_view was introduced in c++17
@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".
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.