visual-studio-codevscode-code-runner

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?


Solution

  • 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.