0

I downloaded and installed MinGW under C:\MinGw and installed g++ and gcc.

If I run g++ --version I get:

g++.exe (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

If I run gcc --version, I get:

gcc (GCC) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying 
conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR 
A PARTICULAR PURPOSE

I'm trying to run a simple helloworld.cpp file from VSCode:

#include<iostream>

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

I've edited the c_cpp_properties.json file as follows:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\MinGW\\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\MinGW\\bin\\g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

But when I go and build/run the file, I get the following:

Starting build...
C:\cygwin64\bin\cpp.exe -fdiagnostics-color=always -g C:\Users\Pippo\Desktop\Programming\CPP\helloworld.cpp -o C:\Users\Pippo\Desktop\Programming\CPP\helloworld.exe
cpp: fatal error: cannot execute 'cc1plus': spawn: No such file or directory
compilation terminated.

Build finished with error(s).

Why is this failing? And why am I seeing Cygwin being called??

EDIT (more stuff I don't get):

The behaviour I showed before happens when I click on Run C/C++ File

enter image description here

But when I click on Run Code it works (and it calls g++):

enter image description here

EDIT (@Yakk - Adam Nevraumont answer): Nope, Cygwin is after g++ in my env vars:

enter image description here

IDK
  • 359
  • 1
  • 16
  • 2
    You need to set the compiler in the VS Code options. `c_cpp_properties.json` is just for linting. – sweenish Aug 09 '22 at 20:54
  • 4
    6 is reeeeally old. Current one is 12. you can install it via msys2 – infinitezero Aug 09 '22 at 20:59
  • Probably because you have Cygwin in the PATH. Unstall your MinGW *and* Cygwin (the former is outdated, the latter you probably don't need), or at least remove them from PATH. Install [MSYS2 as described here](https://stackoverflow.com/q/30069830/2752075), and use it to install an up-to-date GCC. – HolyBlackCat Aug 09 '22 at 21:13
  • 1
    There is `tasks.json` which is separate from `c_cpp_properties.json` and should have some of the relevant settings in it – Nathan Pierson Aug 09 '22 at 21:28

1 Answers1

2

VSCode uses a completely separate tool chain for compiling and for linting and syntax highlighting and similar.

c_cpp_properties.json isn't for compiling.

It gets the compiler typically from your PATH. See here.

Your build task is probably set to the compiler g++, and the first one on the search path (the PATH environment variable) is Cygwin's g++. Alternatively, it can be hard coded in tasks.json.

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524