-1

I am experiencing an issue with my Vscode in C++, where the compiler suggests the iostream header when I type #include< and provides the correct completion for "iostream." However, when I actually include the iostream header (#include ) in my code, the C/C++ (vscode-cpptools) extension complains that it cannot locate the header. However, the code is compiling and running without error both inside Vscode and also from the terminal.

I am using g++ 12.2.0 on Ubuntu 23.0. When I click on #include and go to declaration, it takes me to the "iostream.cpp" file in "/usr/include/c++/12/iostream." This suggests that the header file is present in the standard library.

I have checked my IDE settings and verified that the C/C++ extension is properly installed and configured.

I suspect there might be some system-specific issue or misconfiguration that is causing this problem. Could someone please help me troubleshoot and resolve this issue? Any suggestions or insights into why the compiler suggests the header but cannot locate it during code completion would be greatly appreciated.

Code Sample:


#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;}

Compiler Output/Error:

#include errors detected. Please update your includePath. 
Squiggles are disabled for this translation unit (/home/Desktop/FinDiff/Mmagsolve/hw.cpp).C/C++(1696)
cannot open source file "bits/c++config.h" (dependency of bits/c++config.h")

Thank you for any assistance you can provide!

NB: this is not a duplicate of this question. I'm already able to compile and run my code in Vscode. Here the problem is this #include errors. None of the answers there are helpful to fix this particular problem.

Update: The issue is coming for the vscode-cpptools extension which I use for code completion. Even then, the issue is not that it is not able to find iostream files. Inside the definition of iostream, it is not able to find cannot open source file "gnu/stubs-32.h" :

cannot open source file "gnu/stubs-32.h" (dependency of "bits/c++config.h")C/C++(1696)

This is a problem particular to the Vscode-app tools extension. How can I fix this?

brownser
  • 545
  • 7
  • 25
  • 1
    Is [this](https://github.com/microsoft/vscode-cpptools) what you're using? If so, I would think it would be better to go to the creators of the plug-in and get advice from them. – PaulMcKenzie Aug 03 '23 at 16:52
  • if you are able to compile and the program from visual studio then were are you getting the error from? Which compiler is complaining? – UpAndAdam Aug 03 '23 at 16:56
  • Looks like a duplicate of https://stackoverflow.com/questions/76828716/vscode-giving-include-errors-despite-giving-the-right-includepaths same author.. – UpAndAdam Aug 03 '23 at 17:04
  • 1
    @BoP I'm sorry it does not answer my question. It is clearly mentioned in the post. I don't understand why people try to mark it as duplicate without even reading the question. – brownser Aug 03 '23 at 21:26
  • @UpAndAdam Hi, the error is not during compilation. The error is poping up when the code is being written, from the IntelliSense engine. – brownser Aug 04 '23 at 08:43
  • @PaulMcKenzie yes, the problem is coming from this extension. I have updated the question. – brownser Aug 04 '23 at 09:10
  • "the compiler complains that it cannot locate the header. However, the code is compiling" - That makes no sense whatsoever. – Jesper Juhl Aug 04 '23 at 09:39
  • @JesperJuhl Hi, thank you for pointing out the mistake. It was the `vscode-cpptools` extension that was complaining, not the compiler. – brownser Aug 04 '23 at 09:46

1 Answers1

0

The error was caused by an error in the IntelliSense settings of the vscode-cpptools extension. The IntelliSenseMode was set to linux-gcc-x86 by mistake, which corresponds to 32-bit architecture, while I was on a 64-bit machine. This was changed Go to extensions > "C/C++" (vscode-cpptools) > Extension settings > IntelliSenseMode ( chose appropriate 64-bit mode ) > restart vscode

brownser
  • 545
  • 7
  • 25