4

I'm trying to compile C++ files in Visual Studio Code How to use C/Cpp extension and add includepath to configurations but I'm getting this errors:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit.
cannot open source file "iostream"

I already saw this question and any of the solutions worked for me. Also I recorded a video following the steps of the visual studio code tutorial. Here is my code:

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello World" << endl;
}

And this are my C/C++ settings:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\x86_64-w64-mingw32\\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "${default}"
        }
    ],
    "version": 4
}

3 Answers3

4

open command pallete (ctrl + shift + P) then search edit configuration , select C/C++ edit configuration(UI) . Then scroll down and you will see include path , copy the location of your include path by finding it in file manager , By default the location would be C:\Program Files(x86)\mingw-w64\......\mingw32\include. Set intellisense to default. Now you are ready to enjoy your coding journey.

  • 2
    you mean you are getting same error again –  Jul 10 '21 at 13:14
  • @AndresFelipeMedinaEalo You don't give the person trying to help you much to go on. Expect the quality of the help you get to match the input you give. – Ted Lyngmo Jul 10 '21 at 13:15
  • 2
    what is the location path you paste in include path ? –  Jul 10 '21 at 13:18
  • This two: ${workspaceFolder}/** C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\x86_64-w64-mingw32\include – Andres Felipe Medina Ealo Jul 10 '21 at 13:18
  • 2
    what is the path of your compiler path? –  Jul 10 '21 at 13:21
  • 2
    C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe ------ paste this path location in compiler path –  Jul 10 '21 at 13:22
  • I got this message: [10/7/2021, 8:23:29 a. m.] Unable to resolve configuration with compilerPath "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe". Using "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\gcc.exe" instead. – Andres Felipe Medina Ealo Jul 10 '21 at 13:23
  • 2
    select configuration name to Win32 –  Jul 10 '21 at 13:25
  • That is the current name, I'm going to show all my config in the question. – Andres Felipe Medina Ealo Jul 10 '21 at 13:29
  • have you copied your bin path in your environmental path variable ? –  Jul 10 '21 at 13:31
  • Yes, I guess the environment path is right because I get the expected output if I use `g++ --version` on cmd – Andres Felipe Medina Ealo Jul 10 '21 at 13:35
  • 1
    okay in c/c++ config remove the include path you pasted and leave it as it was (${workspaceFolder}/**) . set compiler path to C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe . configuration name to win 32. intellisense mode to default. –  Jul 10 '21 at 13:38
  • Again it said unable to resolve configuration with compilerPath and It will use the original path – Andres Felipe Medina Ealo Jul 10 '21 at 13:45
  • 1
    now edit configuration s in json file ------- Click the light bulb and then edit the JSON file which is opened. Update paths in includePath (matters if you compile with VS Code) or browse.paths (matters if you navigate with VS Code) or both. after that restart your vs code. –  Jul 10 '21 at 13:52
  • How I update paths in includePath? And I don't see any browse.paths in that file – Andres Felipe Medina Ealo Jul 10 '21 at 13:56
  • 1
    replace your include path with this in json file --- C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\i686-w64-mingw32\include –  Jul 10 '21 at 13:57
  • The errors still appears, why your folder is i686 while mine is x86_64? – Andres Felipe Medina Ealo Jul 10 '21 at 14:00
  • 1
    may be you are using different compiler version –  Jul 10 '21 at 14:06
  • 1
    I tried my best , to resolve your issue . i will let you know if i find solution. –  Jul 10 '21 at 14:08
2

Got the same error. I just disabled the C/C++ Intellisense extension of microsoft and reloaded it.

Pratham_24
  • 29
  • 3
  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32632231) – Deenadhayalan Manoharan Sep 08 '22 at 09:28
0

If you got this problem, Relax, u r probablu 1000th one here ;) I have added screenshots, these are not links to some terrifying third party documentations (;

Solution

1.installation of c++ : check you have the c++ installed, (it dosent come pre-installed! You have to do it) If not install it. If you have installed it, navigate to it, and get the path click on the path at top in file explorer, and Ctrl+C to copy it here is how u get the path

2.path environment variable setup steps: i.left click This pc(in file explorer)here

ii. manage this menu will open

iii. scroll down in the about section, find "Advanced System Settings" and follow along this

V. "edit environment variable" dialogue box will open, click new, then paste the link to the gcc compiler that you installed firstly.

Now, this path is set as environment variable, try running command : gcc --version in command panel, if still there is error, try uploading different paths of gcc.exe to the environment variable "Path". Also, re-starting pc is recommended if path variable change doesn't appear.

Now we start(or restart if it was open) the Vs-code(just a little to go) i. Shift+Ctrl+p then : follow this

ii.then this if the dropdown dosnt show any option, try re-starting vs-code, or pc, re-setting the environment variable step, or re-installing c++ and starting over(in worst case) iii.scroll down the same page, and paste the path to include folders from c++ to text box corrosponding to "Include path" . you have to first get this path, search for folder with name "include", copy and add its path.(many times, ide is capable to automate this step;))

Now try running the code, it must be good to go, but iff it still throws error, try repeating process of adding environment variable, re-staqrting vscode, or even then, re-installing c++.

Shubham
  • 23
  • 5
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 17 '22 at 17:04