4

I installed the C/C++ Extension for Visual Studio Code (ms-vscode.cpptools) and I'm trying to compile a .cpp file, but I keep getting fatal error C1034: iostream: no include path set.

Here is the contents of tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: cl.exe build active file",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/Fe:",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "${file}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Here is the contents of c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "8.1",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}

and here is the exact output:

> Executing task: cl.exe /Zi /EHsc /Fe: c:\Users\User\Documents\C\cpp_workshop-cpp_ex2\main.exe c:\Users\User\Documents\C\cpp_workshop-cpp_ex2\main.cpp <

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

main.cpp

c:\Users\User\Documents\C\cpp_workshop-cpp_ex2\main.cpp(21): fatal error C1034: iostream: no include path set

The terminal process terminated with exit code: 1

Help me, Stack Overflow. You're my only hope!

Ron Inbar
  • 2,044
  • 1
  • 16
  • 26
  • Does [Visual Studio Code `includePath`](https://stackoverflow.com/a/37548293/7582247) help? – Ted Lyngmo Jul 07 '20 at 21:49
  • @TedLyngmo Not really. It says [here](https://code.visualstudio.com/docs/cpp/config-msvc#_compiler-path) that "You only need to add to the Include path array setting if your program includes header files that are not in your workspace or in the standard library path." – Ron Inbar Jul 08 '20 at 05:05
  • 3
    Ok, are you starting VS Code from a Developer Command Prompt for Visual Studio? [issue 3654](https://github.com/microsoft/vscode-cpptools/issues/3654): "_In case you get the error C1034: iostream: no include path set: If you haven't already, start VS code from the Developer Command Prompt that is installed with the MSVC compiler set. If you have everything resolved now, very good. If not, continue. In case you get the error fatal error LNK1112: module machine type 'x86' conflicts with target machine type 'x64', you need to start VS Code from the x64 Developer Command Prompt_" – Ted Lyngmo Jul 08 '20 at 06:52
  • 1
    @TedLyngmo Yes, it works now. Thanks! But it's pretty cumbersome, and it only builds one file at a time. I think I'll migrate to CMake. – Ron Inbar Jul 08 '20 at 10:18
  • Great that it worked! You can probably split the building up in smaller tasks and create a dependency graph in tasks.json too (with linking as the task that `dependsOn` the compilation tasks) - [If you list more than one task in the `dependsOn` property they are executed in parallel.](https://github.com/Microsoft/vscode/issues/23160#issuecomment-422309846) – Ted Lyngmo Jul 08 '20 at 10:31
  • @TedLyngmo Do you know a way to automatically generate `tasks.json` from all the .cpp files in the open folder? – Ron Inbar Jul 09 '20 at 16:19
  • Sorry for the late reply. No I have actually no experience with Visual Studio Code. I'd expect an option in VSCode to add one or many files to the project though. – Ted Lyngmo Jul 23 '20 at 18:14

2 Answers2

4

I had same Problem which solved as Ted Lyngmo says :

open vscode with developer command prompt.

Edit :
When i open vscode with Developer Command Prompt(DCP) it don't gives such an error.
To open DCP follow steps below :
1- Open start menu(WIN key) and start typing "Developer Command Prompt" it should appear there.
2- After opening it write code . and run it. This way you opened vs code from DCP.
3- Navigate desired folder inside vscode and create cpp files there.
4- After you write your "Helloworld.cpp" press CTRL + SHIFT + B, this will compile your code

i hope this helps

yağız ayer
  • 85
  • 1
  • 10
-2

I thought yağız's instructions were pretty clear and this was the one solution that worked for me but for those who requested more details:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

ScottyCov
  • 21
  • 5