3

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?

Payam30
  • 689
  • 1
  • 5
  • 20
  • for multiple files you probably better have make or CMakeLists.txt with cmake-tools ext for vscode – vsh Dec 25 '19 at 01:49
  • Does it mean alot of tweeking? – Payam30 Dec 25 '19 at 19:10
  • Depends on the side of a project, but in case of increasing the amount of files someday you will need to find build system for your project – vsh Dec 26 '19 at 08:28

2 Answers2

12

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.

Payam30
  • 689
  • 1
  • 5
  • 20
1

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.

Xatticus00
  • 146
  • 1
  • 9