vscode-code-runner: C/C++: Can't compile or run when source file path has space(s)
I created a file
D:\Program\USACO\[C2, S3.2] Magic Square.cpp
But when I compile, some errors occurred:
[Running] cd "d:\Program\USACO\" && g++ [C2, S3.2] Magic Square.cpp -o [C2, S3.2] Magic Square && "d:\Program\USACO\"[C2, S3.2] Magic Square
g++: error: [C2,: No such file or directory
g++: error: S3.2]: No such file or directory
g++: error: Magic: No such file or directory
g++: error: Square.cpp: No such file or directory
g++: error: S3.2]: No such file or directory
g++: error: Magic: No such file or directory
g++: error: Square: No such file or directory
g++: fatal error: no input files
compilation terminated.
OS: Win7 SP1 VSCode: 1.19.3 Runner: 0.8.7 5beeedfa674b330537448162dfe9c2330c7eda50
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 2
- Comments: 29 (1 by maintainers)
If you are using Windows, try configuring settings like this:
Pay attention to the extra
'&'
character.If you are using Unix based system, try this (I haven’t tested, but I think this would work):
@tripathi-abhishek use this
In case you run into issues with a bash error like “bash: cd: too many arguments”
Fixed by:- Go to visual studio code settings for code runner and replace cpp key value pair in code-runner.executorMap with the following :- “code-runner.executorMap”: { “cpp”: “g++ $fileName -o $fileNameWithoutExt.exe && ‘./$fileNameWithoutExt.exe’” }
Screenshot:- replace your cpp key value pair with the below mentioned code in “code-runner.executorMap” like:-
Yes in settings.json.
I finally used this command instead:
Here is extract of my settings.json :
Hello, I have the same problem. I’m using Windows, I’m trying to run a simple C++ program, I don’t have spaces anywhere in the path or file name.
If I copy the command as is, and paste it in a cmd.exe then it works without problem 😕
I made changes as suggested by others but nothing worked.
EDIT: Solved! Here is how, maybe it will help others :
Windows Guys! Just Copy Past This to your settings.json file
Hello!
I have a same problem in Mac OS X. Some solution to this bug? If I rename Example 1.cpp to Example1.cpp or Example_1.cpp then, it works ok…
Thank you!
@hanghang0702 sorry I’m late, @Michany you forgot the escape characters, @formulahendry it isn’t the problem on *nix based system the executable file runs with ./"dir"filename ,
I’m not a windows user & I’m not sure if it’s going to work on windows (you’ll probably need to adjust/change some escape characters or something similar). I really hope they edit & fix it in the upcoming version(s).
this works for me
@VipulKhandelwal1999 thanks this worked!
this worked for me. I Am now able to compile and run c cpp and java files(‘&’ is not needed in java though if anyone is wondering)