I installed Visual Studio Code on W10 to run some code with WSL installed ( Ubuntu).
I followed the steps in the following article :
https://code.visualstudio.com/docs/cpp/config-wsl
But I keep receiving the following error message when trying to compile the code in visual Studio Code :
"g++: error: helloworld.cpp: No such file or directory"
There are the configuration for the 3 .json file:
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "/home/marc/projects/helloworld/helloworld.out",
"args": ["-fThreading"],
"stopAtEntry": true,
"cwd": "/home/marc/projects/helloworld/",
"environment": [],
"externalConsole": true,
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"pipeTransport": {
"pipeCwd": "",
"pipeProgram": "c:\\windows\\sysnative\\bash.exe",
"pipeArgs": ["-c"],
"debuggerPath": "/usr/bin/gdb"
},
"sourceFileMap": {
"/mnt/c": "${env:systemdrive}/",
"/usr": "C:\\Users\\Marc\\AppData\\Local\\Packages\\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\\LocalState\\rootfs\\usr\\"
}
}
]
}
tasks.json
{
"version": "2.0.0",
"windows": {
"options": {
"shell": {
"executable": "c:\\windows\\sysnative\\bash.exe",
"args": ["-c"]
}
}
},
"tasks": [
{
"label": "build hello world on WSL",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"/home/marc/projects/helloworld/helloworld.out",
"helloworld.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
My path projects on WSL Ubuntu is :
/home/marc/projects/helloworld/
This folder is empty as Visual Studio Code is supposed to run through WSL in the folder C:\Users\Marc\projects\helloworld.vscode that currently contains:
c_cpp_properties.json
helloworld.cpp
launch.json
tasks.json
How can this be fixed?
Thank you
Make sure you have a C++ compiler installed before attempting to run and debug helloworld.cpp in VS Code. Open helloworld.cpp so that it is the active file. Press the play button in the top right corner of the editor. Choose C/C++: g++.exe build and debug active file from the list of detected compilers on your system.
Make sure your compiler executable is in your platform path ( %PATH on Windows, $PATH on Linux and macOS) so that the C/C++ extension can find it. You can check availability of your C++ tools by opening the Integrated Terminal (Ctrl+`) in VS Code and trying to directly run the compiler.
If anyone have this problem, I've setup gcc with VS Code after reading official tutorial here
I got the same problem, and the solution is to move cpp and header files into project folder (1 folder up), that is outside the ".vscode" folder.
dir structure should looke like this:
-> project dir (project root folder)
-> -> .vscode
-> -> -> json files are here (inside the .vscode)
-> -> helloworld.cpp (project files are here inside project dir)
The same exact problem occurred to me. I came here for the solution but I didn't find one. I tried everything I could do but at last, I made a simple change which solved the problem. I named my code "Quick Sort.cpp" before the error. Now I changed it to "QuickSort.cpp", without giving any spaces in between while naming it. Now it is running successfully. This may or may not be the reason for your error. But make sure you did not do this mistake.
Just don't save your file with any whitespace character i.e. single space/tab ....
Save your file without Space (file name without space) and use c++ extension
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With