Tag Archives: VScode Error

VSCode Use Code Runner plugin can not compile and run the file filename with spaces [How to Solve]

The most annoying thing about using Visual Studio Code to write C++ programs is that the Code Runner plug-in can’t compile and run files with spaces in the file name. This problem has troubled me for a long time. Although it does not affect my learning, too many separators always feel unpleasant. So I studied it carefully.
First create a test program called “hello world”, and then analyze the reason based on the G++ error report in English:

g++.exe: error: hello: No such file or directory
g++.exe: error: world.cpp: No such file or directory
g++.exe: error: world: No such file or directory
g++.exe: fatal error: no input files
compilation terminated.

No such file or directoryIt means that there is no such file or directory, fatal error: no input fileswhich means a fatal error: there is no input file, and then the compilation has been terminated. According to error, we found that the C ++ compiler is hello world.cppas the helloand world.cppthe two documents, my first reaction is the filename with spaces to be enclosed in double quotes. Go to the Code Runner plug-in page, click Settings -> Extended Settings.

After that, find Executor Map and click to edit in setting.json.

Find “cpp” and change it to:

"cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt.exe\" && \"$fileNameWithoutExt.exe\"",

Run hello world.cpp, the compilation is successful, but how to output the file name? I tested it in CMD again. It was able to compile and run the program. The problem was immediately locked in Powershell. I thought that the code of the CMD and Powershell running program must be different, so the failure occurred.

After searching for Baidu, I found out that Powershell should add the symbol (&) in front of it. This is called a call operation.

After adding &, an error message appears again:

It turned out to be added with “.”. The final compile and run code becomes:

"cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt.exe\" && & \".\\$fileNameWithoutExt.exe\"",

VScode: Running the contributed command: What to do when’extension.node-debug.startSession’ failed.

Description:

What to do if you are using VScode and get the error Running the contributed command:’extension.node-debug.startSession’ failed.

This symptom seems to be limited to mac.
In my case it happened on macOS 10.12.4 VScode 1.12.1.

Solution:

In each lunch setting item of launch.json,

“protocol”: “legacy”,

If you add, it will work.

Better solution

Since the specifications of launch.json have changed variously, it may be better to delete it once and recreate it with Auto.
I’ve made tests and about 30 kinds of lunch, so I haven’t done it yet …