Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code-runner configuration for running multiple cpp classes in vscode

I have a cpp project with multiple classes and headers. I was trying to make it compile and run using tasks and lunch.json but I gave up. I realized that a while ago I had a problem with Python interperter and went to code-runner configuration to change the default interperter when working with Python. But there has to be a way to make code-runner work even in cpp when having multiple classes and header. This is what I found in the configuration:

"code-runner.executorMap": {
    "cpp": "cd $dir && g++ -std=c++14 $fileName  -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},

I see that only one file gets compiled. What should I add to the code above to make vscode compile all classes?

like image 734
Payam30 Avatar asked Oct 23 '25 22:10

Payam30


2 Answers

I change that line to

"code-runner.executorMap": {
    "cpp": "cd $dir && g++ -std=c++14 *.cpp  -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},

Now it works like a charm.

like image 75
Payam30 Avatar answered Oct 26 '25 12:10

Payam30


I'll add an enhancement to @Payam30's answer.

"code-runner.executorMap": {
    "cpp": "cd $dir && g++ -std=c++14 $fileName `find . \\( -iname '*.cpp' -not -name '$fileName' \\)` -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},

If you add the find ... portion then any other function directories --- which I like to use to organize my larger codebases --- get included as well, excluding the main file so it isn't repeated.

like image 29
Xatticus00 Avatar answered Oct 26 '25 13:10

Xatticus00