Setting the compiler path on Windows - c++

In my computer c_cpp_properties.json file looks like this,
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
Is the compilerPath and intelliSenseMode are correct ?
or compilerPath should be something like this
C:\MinGW\lib\gcc\mingw32\6.3.0\include\c++
or
C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe",
also intelliSenseMode should be "gcc-x64", or "clang-x64" or "msvc-x64" ?
For instance in Microsoft Vs Code site above code changed to
{
"configurations": [
{
"name": "Win32",
"defines": [
"_DEBUG",
"UNICODE"
],
"compilerPath": "C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
https://code.visualstudio.com/docs/cpp/config-mingw#_configure-the-compiler-path
So the main problem is how can I be sure about the what to use in compilePath
Thanks

To answer your question, in the official Visual Code documentation, you can see that the compiler path and intelliSenseMode are set as shown below. Just make sure to give the right location of g++.exe.
"compilerPath": "C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe",
"intelliSenseMode": "gcc-x64"
Update the question with what issues you are noticing if you have any.

The compilerPath and intelliSenseMode variables serve the purpose of configuring the VSCode editor to provide compilation and IntelliSense services respectively.
compilerPath
Because VSCode isn't a full IDE by itself, it doesn't ship with the compiler it needs to offer the compilation service. Therefore, it needs to be pointed in the direction of a valid C++ compiler. That is the purpose of the compilerPath variable. Testing whether or not the path you provided is correct is easy. Copy and paste it into a terminal (CMD or PowerShell) and see if the resulting output looks something like this:
PS C:\Users\neilb> C:\"Program Files"\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe
g++.exe: fatal error: no input files
compilation terminated.
PS C:\Users\neilb>
This means that the path is valid. If it isn't, locate where your install of MinGW (the library that provides gcc and g++ support on Windows) is. If not already installed, do so.
inteliSenseMode
This tells VSCode what C++ style guide to follow for formatting code and providing linting features. The full list of options here is listed on the VSCode-cpptools GitHub page. What you have currently set should be adequate. (clang-x64)

Related

My Hello World program on VS Code(C++) is not running (#include errors)

I have started learning C++ and am using VS Code and MinGW. I have installed the Microsoft C/C++ Extension.
I tried Hello World code but the following error is shown.
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (D:\CODE\C++\HelloWorld).
cannot open source file "bits/c++config.h" (dependency of "iostream")
The Code I wrote is
#include<iostream>
int main(){
std::cout<<"Hello World";
return 0;
}
My c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
"C:/Users/Hp/Downloads/dlib-19.21.0/dlib-19.21.0/dlib/bits"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/MinGW/bin/gcc.exe",
"cStandard": "c11",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
I have seen similar problems on the internet and tried solving it but wasnt able to do so.
It is the first time i have ever used VS Code and am not familiar with things.

includePath errors in VS Code

I modified the configurations of my C/C++ extension on VS Code. I'm trying to use wxWidgets on my Mac (M1 2020) with the normal x86 version of VS Code (C/C++ IntelliSense doesn't work on ARM). The folder I want to include is in my home folder.
Here's how my config file looks now:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/Users/mario/wxWidgets/include"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang++",
"cStandard": "c11",
"cppStandard": "c++98",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
Now, I get two errors in my include statement:
Update includePath
Unable to open error code "wx/setup.h" of the origin file (dependency of "wx/wx.h")
The IncludePath should contain everything that's needed for that include statement to work, so I have no idea why it's throwing an error. Can anyone help me? I'm pretty new to coding GUIs with external frameworks so I'm confused. Thanks :)

VS code not detecting library (opencv) from vcpkg on linux. How can I link it?

my c_cpp_properties.json config has the path to vcpkg in it.
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${vcpkgRoot}/x64-linux/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64",
"compilerArgs": []
}
],
"version": 4
}
and I have the library installed:
[alexander#alexanderThinkPad vcpkg]$ ./vcpkg install opencv
Computing installation plan...
The following packages are already installed:
opencv[core,dnn,jpeg,png,tiff,webp]:x64-linux -> 4.3.0#1
Package opencv:x64-linux is already installed
however the library is not detected though navigating to the correct directory shows that the file opencv.hpp is present. How can I get VS code to recognize the library?

VSCode C++ Intellisense Squiggles

VSCode is randomly placing squiggles lines under my C++ code. Peak definitions and everything works for the underlined code, the code also compiles, builds, and runs fine. I also don't see the squiggles in Visual Studio 2013 nor QtCreator.
I have tried making changes to my c_cpp_properties.json file. I also used the intellisenseEngine to Tag Parser which does remove the squiggles, but then the coloring everything is wrong (i.e. std::shared_ptr<> is half white and half green). I assume I need to including something that I am missing here. Here is the current state of c_cpp_properties.json:
{
"configurations": [
{
"name": "x86-Debug",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"intelliSenseMode": "msvc-x64",
"configurationProvider": "ms-vscode.cmake-tools",
"compilerPath": "C:/Program Files (x86)/VC/bin/amd64_x86/cl.exe",
"cppStandard": "c++11"
}
],
"version": 4
}
Here are the squiggles that I am seeing. 1

Visual Studio Code C++: unordered_map not found

I was given some C++ files that I need to compile. I'm using Visual Studio Code with the C/C++ and Code Runner extensions on Windows 10. With the following "include" statements:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <unordered_map>
I get the following error:
unordered_map: No such file or directory
I am very new to C++, and haven't been able to find a solution to this problem. I've updated the "includePath" in my c_cpp_properties.json file as follows. I have also tried compiling with Cygwin and Visual Studio Community, but I get the same error. I know the unordered_map .hpp file exists, but the compiler doesn't seem to be finding it.
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17134.0",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
If it's relevant, this is what my tasks.json file looks like:
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "msbuild",
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true",
"/t:build"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
Are my .json files configured properly? I apologize if I'm missing something basic; I've done a lot of searching on how to compile C++ on Windows, and haven't had any success. Thank you in advance for any help.
EDIT:
Here is the full file I'm trying to compile. The executable is meant to be called by a python script.
https://github.com/jorpjomp/sierra-hotel/blob/master/location_routing.cpp
Unordered map is not supported in VS Code by default Microsoft ms-vscode.cpptools. Follow these steps to get over the problem:
Download MinGW from ( https://sourceforge.net/projects/mingw/ ). MinGW is a native Windows port of the GNU Compiler Collection (GCC), with freely distributable import libraries and header files for building native Windows applications.
Mark all the packages for installation.
ss to mark all the packages for installation
Click on the Apply Changes option under the Installation tab
ss of where to click on apply changes
Now, the Environment Variable’s Path is to be updated. Go to Advanced System Settings->Environment Variables.
Edit Path in System Variables Tab.
ss of how to edit Path
Copy the path of the bin folder of MinGW. By default, the path is: C:\MinGW\bin
Paste this new path in the list and click OK.
ss after pasting the bin path into the list
Run the C++ code in VS Code. It will work fine.
ss of vs code working fine at last
You are using msbuild at the moment to build your project. Is this intentional? If you just have "some C++ files" you want to compile, msbuild is an overkill, compile the source directly by either using Mingw's g++ or the Microsoft CL.exe compiler.
So I recommend:
1) Go to http://mingw-w64.org/doku.php/download, download and install mingw and add the path to g++ into your PATH environment variable.
2) In Visual Studio Code create a task.json with the following content:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
c_cpp_properties.json (assuming you store mingw here: C:\mingw\mingw64\bin):
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/mingw/mingw64/bin",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}