dev_tool_tutorials

Tutorials on common developer tools for computer science students.


Project maintained by jeremyglebe Hosted on GitHub Pages — Theme by mattgraham

Visual Studio Code: Multiple File Compilation

Problem

Unlike some IDE softwares (remember, vscode is not a full ide) Visual Studio Code doesn’t have any extremely clear methods to compile multiple files without the user doing so manually. We can address this issue in a few different ways which will be detailed below.

Requirements

The following is assumed about your environment:

If any of the above assumptions are not true of your environment and you are on Windows, follow this tutorial.

3 Methods of Multiple File Compilation

Use the integrated terminal

By far the most direct method of compiling and running code: use the command line. You can open a terminal within VSCode by pressing CTRL+`. Once you have your terminal open, we can use commands to compile your files and run the program.

That’s it! You should have the output of your program in your terminal. Now you just have several thousand bugs and a few hundred debugging statements to get through and you’re done.

Code Runner’s Executor Map

This method is simple. When you run something using Code Runner, you’ll notice that is shows a command being executed in your output. That’s because code runner is really just automatically executing some commands for you. We can configure what command it uses in something called the executor map. Don’t worry, you don’t have to know command line for this one, just use the command I’ve provided.

Preprocessor Directive: ‘include’

With some careful placement of #include preprocessor directives, we can make sure to include and compile all our files just by compiling our main .cpp file. For classes, your .h file will need to include the .cpp implementation file. Now when you include the .h you get the .cpp as well. Your .h file will also need to include #pragma once so it isn’t included multiple times. If I have a class called A divided into definition file A.h and A.cpp, with my program’s main functionality being found in main.cpp, I would need each file to look something like this: