Skip to content

#include errors detected ... cannot open source file "iostream #1041

Closed
@NikoGP

Description

@NikoGP

Hello, so I am new to coding and wanted to use VS Code to code in C++, so I installed it, installed C/C++ IntelliSense v0.12.4 and followed instructions on the VS Code website to make a c_cpp_properties.json file and copied the code into it like they said. When I open my .cpp project that I had made in notepad++, I get the error:
"#include errors detected. Please update your includePath. IntelliSense features for this translation unit (directory\file.cpp) will be provided by the Tag Parser. (9, 1)
cannot open source file "iostream" (9, 1)"

My .cpp code
`#include

using namespace std;

int main()
{
string firstName, lastName;
double hourRate, numHours;

    cout << "+----------------------------------------+" << endl;
    cout << " Your first name and last name: ";
    cin >> firstName >> lastName;
    cout << " Your hourly rate: ";
    cin >> hourRate;
    cout << " Number of hours worked last week: ";
    cin >> numHours;
    cout << endl;
    
    double regPay, overTPay, gPay, socSec, med, netPay;
    if (numHours <= 40)
    {
        regPay = hourRate * numHours;
        gPay = regPay;
        overTPay = 0;
    }
        else
        {
            double oTHours;
            oTHours = numHours - 40;
            regPay = hourRate * (numHours - (numHours - 40));
            overTPay = (hourRate * 1.5) * oTHours;
            gPay = regPay + overTPay;
        }
    socSec = gPay * 0.062;
    med = gPay * 0.0145;
    netPay = gPay - (socSec + med);
    cout << "+----------------------------------------+" << endl << endl;
    cout << " Pay Stub\n" << " Regular pay  $" << regPay << endl;
    cout << " Overtime pay $" << overTPay << endl;
    cout << " Gross pay    $" << gPay << endl;
    cout << " Social Sec.  $" << socSec << endl;
    cout << " Medicare     $" << med << endl;
    cout << " Net Pay      $" << netPay << endl << endl;
    cout << "+----------------------------------------+" << endl << endl;
    cout << " Pay to: " << firstName << " " << lastName << endl;
    cout << " Total Pay: $" << netPay << endl << "\t\t\t   ";
    cout << "Signed: P inc." << endl;
    cout << "+----------------------------------------+" << endl;
    
    return 0;
}`

My c_cpp_properties.json file

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/usr/include",
                "/usr/local/include",
                "${workspaceRoot}"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "/usr/include",
                    "/usr/local/include",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ]
        },
        {
            "name": "Linux",
            "includePath": [
                "/usr/include",
                "/usr/local/include",
                "${workspaceRoot}"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "/usr/include",
                    "/usr/local/include",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE"
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "path": [
                    "${workspaceRoot}",
                    "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ],
    "version": 3
}

Also, when I hover over the "" this shows up:
"#include errors detected. Please update your includePath. IntelliSense features for this translation unit (E:\Stuff\CS11-Things\Homeworks\A3\paycheck.cpp) will be provided by the Tag Parser.
cannot open source file "iostream""

Let me know if you need any more information

Activity

sean-mcmanus

sean-mcmanus commented on Sep 18, 2017

@sean-mcmanus
Contributor

Your includePath only has ${workspaceRoot}. You need to add the path to your system directories. If you're using MinGW, see https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/MinGW.md .

GiBg1aN

GiBg1aN commented on Sep 19, 2017

@GiBg1aN

If you are using Linux you have to add the path /usr/include/linux

ZoeVonFeng

ZoeVonFeng commented on Sep 20, 2017

@ZoeVonFeng

I had same issue on windows, after I add the "C:\\cygwin64\\lib\\gcc\\x86_64-pc-cygwin\\6.4.0\\include\\c++" at includePath, I got this error: cannot open source file "bits/c++config.h" (dependency of "iostream")

bobbrow

bobbrow commented on Sep 20, 2017

@bobbrow
Member

What does gcc tell you the include path should be? Run this command and make sure all of the paths printed out are listed in your c_cpp_properties.json: gcc -v -E -x c++ -

NikoGP

NikoGP commented on Sep 20, 2017

@NikoGP
Author

@sean-mcmanus after adding the code from the link you gave it still complains, I didn't add "C_Cpp.intelliSenseEngine": "Default" to my settings.json file because I have no clue where it is. Anyway, this is the new error I am getting.
"#include errors detected. Please update your includePath. IntelliSense features for this translation unit (E:\\program.cpp) will be provided by the Tag Parser. (9, 1) cannot open source file "iostream" (9, 1)"

sean-mcmanus

sean-mcmanus commented on Sep 20, 2017

@sean-mcmanus
Contributor

@NikoGP Go to File->Preferences->Settings and search for "intelliSenseEngine" to find the setting. You have "Default" set already though. Did you run the gcc command @bobbrow mentioned? Can you provide your updated c_cpp_properties.json? You basically need to find where your iostream header is getting pulled from by your compiler and add the path to the includePath setting (and make sure the defines are correct). Does Go to Definition work on the header file? If so, that means the iostream file was found via a recursive search of your browse.path setting.

NikoGP

NikoGP commented on Sep 20, 2017

@NikoGP
Author
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceRoot}"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ]
        },
        {
            "name": "Linux",
            "includePath": [
                "/usr/include",
                "/usr/local/include",
                "${workspaceRoot}"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "/usr/include",
                    "/usr/local/include",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
            "configurations": [
                {
                    "name": "Win32",
                    "intelliSenseMode": "clang-x64",
                    "includePath": [
                        "${workspaceRoot}",
                        "C:/MinGW/lib/gcc/mingw32/5.3.0/include/c++",
                        "C:/MinGW/lib/gcc/mingw32/5.3.0/include/c++/mingw32",
                        "C:/MinGW/lib/gcc/mingw32/5.3.0/include/c++/backward",
                        "C:/MinGW/lib/gcc/mingw32/5.3.0/include",
                        "C:/MinGW/include",
                        "C:/MinGW/lib/gcc/mingw32/5.3.0/include-fixed"
                    ],
                    "defines": [
                        "_DEBUG",
                        "UNICODE",
                        "__GNUC__=5",
                        "__cdecl=__attribute__((__cdecl__))"
                    ],
                    "browse": {
                        "path": [
                            "C:/MinGW/lib/gcc/mingw32/5.3.0/include",
                            "C:/MinGW/lib/gcc/mingw32/5.3.0/include-fixed",
                            "C:/MinGW/include/*"
                        ],
                        "limitSymbolsToIncludedHeaders": true,
                        "databaseFilename": ""
                    }
                }
            ],
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 3
}

Here is my current c_cpp_properties.json file, when I hover over the "{" before configurations Win32 it says "missing property "name""
Also, I installed cygwin before installing MingW, I'm not sure if that messes anything up or not

bobbrow

bobbrow commented on Sep 20, 2017

@bobbrow
Member

I reformatted your comment. There is a "configurations" element inside your "configurations" which is invalid syntax for the c_cpp_properties.json file. Fix it like below:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceRoot}"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ]
        },
        {
            "name": "Linux",
            "includePath": [
                "/usr/include",
                "/usr/local/include",
                "${workspaceRoot}"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "/usr/include",
                    "/usr/local/include",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
                    "name": "Win32",
                    "intelliSenseMode": "clang-x64",
                    "includePath": [
                        "${workspaceRoot}",
                        "C:/MinGW/lib/gcc/mingw32/5.3.0/include/c++",
                        "C:/MinGW/lib/gcc/mingw32/5.3.0/include/c++/mingw32",
                        "C:/MinGW/lib/gcc/mingw32/5.3.0/include/c++/backward",
                        "C:/MinGW/lib/gcc/mingw32/5.3.0/include",
                        "C:/MinGW/include",
                        "C:/MinGW/lib/gcc/mingw32/5.3.0/include-fixed"
                    ],
                    "defines": [
                        "_DEBUG",
                        "UNICODE",
                        "__GNUC__=5",
                        "__cdecl=__attribute__((__cdecl__))"
                    ],
                    "browse": {
                        "path": [
                            "C:/MinGW/lib/gcc/mingw32/5.3.0/include",
                            "C:/MinGW/lib/gcc/mingw32/5.3.0/include-fixed",
                            "C:/MinGW/include/*"
                        ],
                        "limitSymbolsToIncludedHeaders": true,
                        "databaseFilename": ""
                    }
        }
    ],
    "version": 3
}
NikoGP

NikoGP commented on Sep 20, 2017

@NikoGP
Author

Even using the code above @bobbrow VSC still complains and says;
"#include errors detected. Please update your includePath. IntelliSense features for this translation unit (E:\program.cpp) will be provided by the Tag Parser. (9, 1) cannot open source file "iostream" (9, 1)"
in the problems section below my code

Screenshot of output

bobbrow

bobbrow commented on Sep 20, 2017

@bobbrow
Member

What version of MinGW are you using? In your first post, it looked like you had 6.3.0 in your include path. In your most recent post, it looked like you pasted in include paths for 5.3.0 from our MinGW page.

NikoGP

NikoGP commented on Sep 20, 2017

@NikoGP
Author

Okay, I think that my problem lies in the fact that I had installed cygwin prior to MingW, and then I incorrectly installed the required packages for MingW to properly function.
Is there somewhere that I can find what packages I need to install for VS Code to work properly with MingW?

smithalexk

smithalexk commented on Sep 27, 2017

@smithalexk

I am also having the issue seen by @NikoGP with my Intellisense after upgrading to v0.13.0. When I turned on the "Default" setting on the Intellisense engine, I keep receiving an iostream include path error (see attached files). I'm running MacOS 10.12.6, and have updated the LLVM engine as well.

The error under the iostream include is:
#include errors detected. Please update your includePath. IntelliSense features for this translation unit /pathToProgram/) will be provided by the Tag Parser.
cannot open source file "wchar.h" (dependency of "iostream")

Simple "Hello World" example showing the error:
helloworld_example

My c_pp_properties.json file:
c_pp_properties

bobbrow

bobbrow commented on Sep 27, 2017

@bobbrow
Member

@smithalexk, for me, this file resides in /usr/include. What does clang -Wp,-v -E -xc -x c++ /dev/null show as your include path? The "includePath" in your c_cpp_properties.json file should match that.

37 remaining items

Ladinstar

Ladinstar commented on Feb 28, 2018

@Ladinstar

Hello here ! I have the same problem but i use codeblocks in windows to compile. Help me please !

sean-mcmanus

sean-mcmanus commented on Feb 28, 2018

@sean-mcmanus
Contributor

@Ladinstar Can you provide more repro info, preferably in a new issue: https://github.com/Microsoft/vscode-cpptools/issues/new .

Ladinstar

Ladinstar commented on Mar 2, 2018

@Ladinstar

thank you i have founded the solution !

admercs

admercs commented on May 29, 2018

@admercs

Note to MacOS users, if you are using gcc version 8.1.0 (for example) from Homebrew, your MacOS configuration should look like this:

{
    "name": "Mac",
    "browse": {
        "path": [
            "${workspaceRoot}"
        ],
        "limitSymbolsToIncludedHeaders": true
     },
     "includePath": [
         "${workspaceRoot}/**",
         "/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0",
         "/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/x86_64-apple-darwin16.7.0"
     ],
     "defines": [],
     "compilerPath": "/usr/local/Cellar/gcc/8.1.0/bin/gcc-8",
     "cStandard": "c11",
     "cppStandard": "c++17",
     "intelliSenseMode": "clang-x64"
}

Very simple. You do not need to include headers from XCode. Do not set compilerPath to /usr/local/bin/gcc-8, as this is a symbolic link that may mess up IntelliSense. If you are still having issues as I did, set the following user setting in settings.json as others have to get around a recent issue: "C_Cpp.intelliSenseEngine": "Tag Parser",

prdas31

prdas31 commented on Aug 12, 2018

@prdas31

What include files needed to run my code using cl.exe from MSVS 2015?

I've included these folders in c_cpp_properties.json:

"C:/Program Files (x86)/Windows Kits/8.1/Include/shared",
"D:/Program Files (x86)/Microsoft Visual Studio/2017Community/VC/include",
"D:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/*",
"D:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.13.26128/include",
"D:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt",
"D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/include",
"D:/Program Files (x86)/Mirucrosoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/atlmfc/include",
"D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/crt/src/x64",

But still I get an error while try to build:

> Executing task: & 'D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx64/x64/cl.exe' 'h:\C++ Programs\ExBox01.cpp' <

Microsoft (R) C/C++ Optimizing Compiler Version 19.13.26128 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

ExBox01.cpp
h:\C++ Programs\ExBox01.cpp(2): fatal error C1034: iostream: no include path set
The terminal process terminated with exit code: 1
sean-mcmanus

sean-mcmanus commented on Aug 13, 2018

@sean-mcmanus
Contributor

@adam-erickson There's a crashing bug with gcc 8.1 you may be hitting (#2328 ) -- our latest insider release has the fix: https://github.com/Microsoft/vscode-cpptools/releases/tag/v0.17.8-insiders .

@prdas31 Our extension doesn't currently support any build features -- the c_cpp_properties.json is for the IntelliSense feature and not actual compiling. For building with MSVS 2015, you may need to build from the developer command prompt that ships with VS.

prdas31

prdas31 commented on Aug 15, 2018

@prdas31

@prdas31 Our extension doesn't currently support any build features -- the c_cpp_properties.json is for the IntelliSense feature and not actual compiling. For building with MSVS 2015, you may need to build from the developer command prompt that ships with VS.

Thanks a lot for the clarification and suggestion. I now use build files to include the paths like this:

if exist "D:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" (
    call "D:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64
) else (
    call "D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
)

This idea is taken from an VSCODE extension called Easy C/C++ Project.

Thanks.

leslienguyn

leslienguyn commented on Sep 29, 2018

@leslienguyn

[issue moved]

bobbrow

bobbrow commented on Oct 1, 2018

@bobbrow
Member

@leslienguyn, I moved your issue to #2582. This issue is closed.

locked and limited conversation to collaborators on Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @1st@admercs@GiBg1aN@NikoGP@mohamedotnet

        Issue actions

          #include errors detected ... cannot open source file "iostream · Issue #1041 · microsoft/vscode-cpptools