-1

I'm having some issues getting my installation of VS Code to compile even a basic C++ script.

The way I installed everything (and I have done this multiple times over) is by first installing the visual studio installer to the default location. Once that was complete, I installed Visual Studio 2019 Community with the desktop c++ development, and c++ game development modules into their default install directories as well (These include the most recent windows 10 sdk, and C runtime environment, etc). I then installed VS Code to the default location too.

To open VS Code I use the developer command prompt and type 'code' then hit enter. I then also installed the Microsoft C/C++ extension. I created a new file, let's call it 'example.cpp' which contains the following:

int main()
{
    return 0;
}

When I compile this from the VS Code terminal after navigating to the file's location and running the 'cl example.cpp' command, I get the following error:

LINK : fatal error LNK1104: cannot open file 'kernel32.lib'

As I've discovered this is due to the %LIB% and %LIBPATH% variables not referencing the Windows 10 SDK libraries installed on the system. I had managed to get around this by manually setting 'LIB' and 'LIBPATH' system environment variables pointing to the correct folders, however I know that that's a pretty messy way to fix it and might mess things up once I move towards the Unreal engine. With that being said, I was able to compile and run the above code without issue until I tried a simple Hello World program:

#include <iostream>

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

Where when compiled produced the following error:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\yvals.h(12):
fatal error C1083: Cannot open include file: 'crtdbg.h': No such file or directory

This leads me to believe that the %INCLUDE% path also hasn't been set to point to the Windows 10 SDK includes, and to confirm this I went into the Developer Command Prompt and ran a few echo commands, and this is my results:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>echo %INCLUDE%
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\ATLMFC\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include;

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>echo %LIBPATH%
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\ATLMFC\lib\x86;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\lib\x86;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\lib\x86\store\references;C:\Windows\Microsoft.NET\Framework\v4.0.30319;

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>echo %LIB%
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\ATLMFC\lib\x86;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\lib\x86;

As far as I'm currently aware, these paths should have a reference to the SDK's include folder, as well as the bin folders that contains the kernel32.lib file. Now without manually creating system environment variables again, I'm wondering if there's a command I can use within the developer console that will add the SDK paths that are needed to the %INCLUDE%, %LIB%, and %LIBPATH% variables? Or am I simply going about this completely wrong?

Any and all advice is more than appreciated, and I'm more than happy to provide further information if necessary.

Update: as requested, my VS Code JSON files.

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}
  • Maybe you should show your `Visual Studio Code` json files so someone can tell you what is wrong with them. – drescherjm May 07 '20 at 20:28
  • Where would I find those? I apologize, I'm new to VS Code – Keegan Heffernan May 07 '20 at 20:47
  • I've found c_cpp_properties.json, is there more? – Keegan Heffernan May 07 '20 at 21:04
  • This should help you understand how to use VS Code with MSVC compiler: [https://code.visualstudio.com/docs/cpp/config-msvc](https://code.visualstudio.com/docs/cpp/config-msvc) – drescherjm May 07 '20 at 21:11
  • That page seems to assume that I'm working within a workspace. I am following an online course, and at no time have I been instructed to create a workspace folder yet and the instructor is able to compile just a standalone .cpp file. I'm just trying to follow along. – Keegan Heffernan May 07 '20 at 21:24
  • even following that article by navigating to the folder where my projects will be and opening code from there (to generate the 3 json files) only the c_cpp_propertis.json file is created and I continue to get the same 'cannot open include file: 'crtdbg.h' error from before. – Keegan Heffernan May 07 '20 at 21:33
  • Is `10.0.18362.0` your SDK version? – drescherjm May 07 '20 at 21:35
  • Yes. Would it make a difference if my project file was on my D drive while all my installs are on the C drive? – Keegan Heffernan May 07 '20 at 21:36
  • I don't think so. – drescherjm May 07 '20 at 21:39
  • I feel like an absolute idiot right now, but the issue was that I was not running the developer command prompt as an administrator. – Keegan Heffernan May 07 '20 at 21:53
  • That is weird, you should not have to do that ever. I don't have a good explanation for why this fixes the issue. – drescherjm May 07 '20 at 21:54

1 Answers1

0

Make sure you run the Developer Command Prompt as an administrator.