Vscode-code-runner: code runner can't compile multiple source files

Created on 19 Jan 2019  Â·  2Comments  Â·  Source: formulahendry/vscode-code-runner

For example, here is a simplified version of the executor map for cpp files:
"cpp": "g++ $fileName -o $fileNameWithoutExt"

$filename will only compile the current file, which doesnt work for projects with multiple source (*.cpp) files. Is there a parameter that can be used in place of $filename to compile all *.cpp files in the working/project directory?

enhancement

Most helpful comment

Hi @lemon07r , I have plan to improve this. I am not an expert of C++ and need you insight here. If you change executor to g++ *.cpp -o $fileNameWithoutExt, will multiple source (*.cpp) files be compiled?

All 2 comments

Hi @lemon07r , I have plan to improve this. I am not an expert of C++ and need you insight here. If you change executor to g++ *.cpp -o $fileNameWithoutExt, will multiple source (*.cpp) files be compiled?

Hi @lemon07r , I have plan to improve this. I am not an expert of C++ and need you insight here. If you change executor to g++ *.cpp -o $fileNameWithoutExt, will multiple source (*.cpp) files be compiled?

This works for me. Took a bit of configuring to get this extension to work on windows with msys2's mingw64 toolchain.

A few notes, with default extension settings, attempting to compile would give me an unrecognized command error, even though a quick g++ -v command in the integrated terminal would show that I have gcc/g++ 8.2.1.
I'm assuming this is cause the extension was trying to use the default msys subsystem to compile instead of the mingw64 subsystem. My integrated shell (msys2) is setup as such:

"terminal.integrated.shell.windows": "C:\\msys64\\usr\\bin\\bash.exe",

"terminal.integrated.shellArgs.windows": [
     "--login",
 ], 
"terminal.integrated.env.windows": {
     "CHERE_INVOKING": "1",
     "MSYSTEM": "MINGW64",
 }

I was able to resolve this issue by setting the extension to run in terminal code-runner.runInTerminal": true,.

After this I started getting an error for too many arguments so I just simplified the executor setting to cpp": "g++ $fileName -o $fileNameWithoutExt, which worked but only compiled from a single source file.
After trying your suggestion I have a working configuration using cpp": "g++ *.cpp -o $fileNameWithoutExt" which does compile with all the source files in the working directory.

This will only compile without running, so my crude method for getting it to run after compiling is:
"cpp": "g++ *.cpp -o $fileNameWithoutExt && ./$fileNameWithoutExt.exe"

Just wondering, is there any way to compile in the integrated terminal but then run the compiled code in a new window/external terminal?
EDIT: Nevermind, figured it out. "cpp": "g++ *.cpp -o $fileNameWithoutExt && start bash -c './$fileNameWithoutExt.exe'"

Was this page helpful?
0 / 5 - 0 ratings