question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

C/C++: Can't compile or run when source file path has space(s)

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:29 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
Yuki-Nagatocommented, Jul 14, 2018

If you are using Windows, try configuring settings like this:

"code-runner.executorMap": {
    "cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt.exe\" && & \"$dir$fileNameWithoutExt.exe\""
}

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):

"code-runner.executorMap": {
    "cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt\" && \"$dir$fileNameWithoutExt\""
}
3reactions
VipulKhandelwal1999commented, Nov 9, 2020

@tripathi-abhishek use this

In case you run into issues with a bash error like “bash: cd: too many arguments” 2020-11-07 (5)

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:- 2020-11-07 (3)

Read more comments on GitHub >

github_iconTop Results From Across the Web

C++ file name with space causes error in Visual Studio Code
If you are using Windows, try configuring settings like this in your Setting.JSON "code-runner.executorMap": { "cpp": "cd $dir && g++ ...
Read more >
g++ compiler : unable to compile - c++ - Super User
and I'm trying to run a very simple program to display "hello", to see wether it would work. The problem is that whatever...
Read more >
How To Compiling C Program And Creating Executable File ...
Next, open your terminal(ctrl+t) and type cd location and press enter.Now compile your c file using this command line gcc filename.c .Now a.out ......
Read more >
Getting Started with the LLVM System
Local LLVM Configuration; Compiling the LLVM Suite Source Code; Cross-Compiling LLVM; The Location of LLVM Object Files; Optional Configuration Items.
Read more >
Using make to Compile Programs
Most C programs, however, are compiled from several source files. ... Each executable is to be built from a source file that has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found