1

I'm using Code Runner extension in VS Code to run C++ code and it's using the wrong terminal command to do so. I'm using git-bash in VS Code and Windows 10.

This is the command in terminal:

Douglas@LAPTOP-6BSNLLDB MINGW64 /c/path (master)
$ cd "c:\path\" && g++ HelloWorld.cpp -o HelloWorld && "c:\path\"HelloWorld
bash: cd: c:\path" && g++ HelloWorld.cpp -o HelloWorld && c:path"HelloWorld: No such file or directory

As you can see, it's using cd and g++ correctly, but the command to actually run the .exe file is wrong. Shouldn't it be "c:\path\HellowWorld.exe"?

How can I change this? It works correctly with python.

If I can't, how do I run C++ code within VS Code?

Nii Miyo
  • 21
  • 4
  • 1
    Bash doesn't know anything about Windows path names or .exe files. Ought to be /c/path/HelloWorld – Hans Passant Jan 25 '20 at 17:19
  • Do you have to use git-bash terminal for compiling the C++ program? Looks like the commands are coming from extension itself and they are compatible with Windows terminal, not with bash. – Chitrang Jan 25 '20 at 17:21
  • I was using bash because a friend told me to since I could use it on Linux and Windows. Changing it to powershell worked fine, thanks. – Nii Miyo Jan 25 '20 at 23:34

3 Answers3

1

Seems like you are using git-bash instead of PowerShell.

you only need to use

"code-runner.terminalRoot": "/",

VSCode: Code Runner extension is unable to execute the code on git bash terminal?


Change setting to

"code-runner.executorMap":{
 "cpp": "cd $dirWithoutTrailingSlash && g++ $fileName -o $fileNameWithoutExt && ./$fileNameWithoutExt",
}

also c's: ( I use tcc)

"code-runner.executorMap":{
 "c": "cd $dirWithoutTrailingSlash && tcc -run $fileNameWithoutExt.c",
}
AsukaMinato
  • 1,017
  • 12
  • 21
0
$ cd /d "c:\path\" && g++ HelloWorld.cpp -o HelloWorld && HelloWorld
  • Or..
$ cd /d "c:\path\" && g++ HelloWorld.cpp -o HelloWorld.exe && HelloWorld
Io-oI
  • 2,514
  • 3
  • 22
  • 29
0

What wuyudi said before isn't false, but I think instead of

"code-runner.termnalRoot":"/",

you should use

"code-runner.terminalRoot":"/mnt/"

it's working fine for me so I hope it will work for the others too.

rodlsldor
  • 1
  • 1