When attempting to compile a C++ program in VS Code I'm getting an error. The Executing task is: cl.exe /Zi /EHsc /Fe: 'c:\Users\Me\Documents\cpp\VRP\program.exe' 'c:\Users\Me\Documents\cpp\VRP\program.cc'
The error I get is:
program.cc
c:\Users\Me\Documents\cpp\VRP\program.cc(1): fatal error C1083: Cannot open include file: 'linear_solver/linear_solver.h': No such file or directory
The terminal process terminated with exit code: 1.
The first line in my program.cc file is: #include "linear_solver/linear_solver.h"
The Path "C:\Users\Me\Documents\CPP\or-tools_VisualStudio2019-64bit_v7.6.7691" is in my Environment Variables. The full path to where the header file "linear_solver.h" is located is "C:\Users\Me\Documents\cpp\or-tools_VisualStudio2019-64bit_v7.6.7691\include\ortools\linear_solver\". How do I direct the Microsoft C++ (MSVC) "cl.exe" compiler to locate that directory/file or modify the include statement to work in Visual Studio Code?
My c_cpp_properties.json file is:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Users/Me/Documents/cpp/or-tools_VisualStudio2019-64bit_v7.6.7691/include/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64",
"compilerArgs": []
}
],
"version": 4
}
My launch.json is:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "cl.exe build active file"
}
]
}
My tasks.json is:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"problemMatcher": ["$msCompile"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Related
Note that I'm using Windows 10 x64, MinGW 9.2.0, VSCode 1.54.1.
My goal is to build and run multiple .cpp files in current folder and different levels subfolders I use. I've tried it configuring tasks.json and c_cpp_properties.json files with help of these articles: https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference
https://code.visualstudio.com/docs/cpp/config-mingw
VS Code will not build c++ programs with multiple .ccp source files
I tried to configure my c_cpp_properties.json by adding this instruction:
"includePath": [
"${workspaceFolder}/*"
]
And I modified also my tasks.json like this:
"args": [
"-std=c++17",
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
]
It actually works for the case I would like to build multiple .cpp files in the main directory. I have a folder vscode_prj, then I have .vscode inside (I attach all my configuration files here), and all files I have inside vscode_prj are build OK, but if I try to create a new folder inside vscode_prj, for example vscode_prj/project1 and I have a few .cpp files inside project1 it's not working and I can't build these files. I just recieve this error:
g++.exe: error: C:\Users\username\folderfolder\_prj\vscode_prj\*.cpp: Invalid argument
g++.exe: fatal error: no input files
compilation terminated.
So, as I understand, compiler just can't find my source files inside subfolder. And it doesn't matter if I have one source file in this folder or several, it's just not build. I appreciate any help and excuse me for my English, it's my first question here, because I just don't know what to do. Thanks.
Attachments:
vscode_prj/.vscode/c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/*"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "gnu17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"compilerArgs": [
"-std=c++17"
]
}
],
"version": 4
}
vscode_prj/.vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-std=c++17",
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\MinGW\\bin\\g++.exe"
}
]
}
vscode_prj/.vscode/launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Сборка и отладка активного файла",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Включить автоматическое форматирование для gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
vscode_prj/.vscode/settings.json:
{
"files.associations": {
"*.tcc": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"string": "cpp",
"iomanip": "cpp"
}
}
I get the error "fatal error: GLFW/glfw3.h: No such file or directory" when i try to compile this simple code:
#include <GLFW/glfw3.h>
int main()
{
}
I'm using Visual Studio Code 2019 with mingW g++ 8.1.0, the IDE is able to locate "GLFW/glfw3.h" he can even open it when doing a right click 'Go to Definition' but the compilator can't, how to resolve this error ?
EDIT: There are the JSON files used to compile the code:
launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Mingw\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
c_cpp_propreties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"/VulkanSDK/1.2.154.1/Include/**",
"/Projects/Libraries/glm/**",
"/Projects/Libraries/glfw-3.3.2/include/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:\\Mingw\\mingw32\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "g++",
"args": [
"-o",
"main",
"-g",
"main.cpp"
],
"group": {"kind": "build", "isDefault": true}
}
]
}
I'm first time learning c++ and have followed the guide on https://code.visualstudio.com/docs/cpp/config-mingw but I still cannot successfully compile and run a basic program. Here are my configurations, launch and tasks files.
The only issue I think could be occurring is that I have the code in my E: drive. Although I don't think this should be an issue. Any and all help appreciated.
Configurations:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
Launch:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/helloworld.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Tasks:
{
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "gcc",
"args": [
"-g",
"-o",
"helloworld",
".vscode"
"helloworld.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Output is:
> Executing task: gcc -g -o helloworld .vscode helloworld.cpp <
gcc.exe: error: helloworld.cpp: No such file or directory
The terminal process terminated with exit code: 1
Terminal will be reused by tasks, press any key to close it.
I've been wrestling with the .json settings in VS Code for some hours now and I'm pretty lost. All I want to do is link pdcurses to my project so I can start coding. I have intellisense set up, but the #include statement is throwing "curses.h: No such file or directory":
The .jsons:
settings.json:
{
"files.associations": {
"iostream": "cpp",
"vector": "cpp"
}
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\Visual Studio Code Projects\\pdcurs39/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\Mingw-w64\\mingw64\\bin\\g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"forcedInclude": [],
"browse": {
"path": []
}
}
],
"version": 4
}
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "build RL Test",
"type": "shell",
"command": "g++",
"args": ["-g", "-o", "RLTest", "RLTest.cpp"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
launch.json:
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/RLTest.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Mingw-w64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Normal C++ packages are working fine. pdcurses is installed at C:\Visual Studio Code Projects\pdcurs39\ with a default mingw-w64 make in the wincon folder.
I think the issue is with not including the pdcurses.a file, but im not sure how to go about linking that...
I'm setting up an IDE using Visual Studio Code for C++ and I have already downloaded and installed all the packages in MinGW Compiler and Git for using bash shell.
I followed this tutorial--> https://code.visualstudio.com/docs/cpp/config-mingw#_configure-debug-settings
However, there were several small details that differed in my case as i progressed through the tutorial for which I'm not aware of their impact(as I am a beginner):
c_cpp_properties.json was a little different in my case.
My code was this:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c11",
"intelliSenseMode": "gcc-x64",
"compilerPath": "C:\\MinGW\\bin\\g++.exe"
}
],
"version": 4
}
In tutorial under configure debug settings, it states: 'Note that the program name helloworld.exe matches what you specified in tasks.json'. On the contrary I had specified 'helloworld.cpp' instead of 'helloworld.exe' in tasks.json
Still I finished the tutorial, and while debugging as said in the tutorial, I got an error stating, helloworld.exe does not exist.
I'd be grateful if someone can provide some insights and ways to deal with these errors.
Please keep in mind that I'm a beginner while answering. Thank You.
Edit: The code for the file tasks.json that I'm using:
{
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"helloworld",
"helloworld.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
The code for the file launch.json that I'm using:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/helloworld.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}