Using Visual Studio Code for C in CSC173
Nora Goodman Fall 2023

Included VSCode features that make it work well for CSC173

Disadvantages to using VSCode for 173

Setting up VSCode

Vscode’s magical keyboard shortcut

Windows Instructions

Note: These instructions are basically just getting WSL setup which will take a while. But, you’ll have it all set up and will be very convenient for development in any other language.

What is WSL?

From Wikipedia:

Windows Subsystem for Linux (WSL) is a feature of Windows that allows developers to run a Linux environment without the need for a separate virtual machine or dual booting.

If you’ve never used Linux, it’s just an operating system like Windows or Mac, but it’s free and good for programming. You’ll be using a feature of Windows that creates a Linux environment.

“Why should I use it for this course?”

Installing WSL

A couple Linux commands you’ll need to run

The fastest way to get a lot of software updated and installed onto your Linux environment is by using the package manager in your command line.

First you’ll need to update all the software on your Linux environment.

In your terminal, type sudo apt update

Here’s what that means:

Once that’s ready, you can type sudo apt upgrade, which will upgrade all the software in your Linux environment.

Now we need to install the tools we need for C development. To do this, type:

sudo apt install gcc gdb make valgrind

Here’s what you just installed:

gccThe “GNU Compiler Collection”, a popular free C compiler
gdbThe “GNU Debugger”, a popular C debugger
makeA tool that will ensure consistency with compiling everything together
valgrindA program that will let you check for memory leaks before you submit your assignment (optional, but it’s a nice sanity check if you have time to get it done)

Set up VSCode for WSL

Instructions for Windows and Mac now that everyone is on the same page

Install necessary VSCode extensions

On the left toolbar of VSCode, you’ll see an icon for some building blocks. That’s where you can install extensions.

Search for and install the “Makefile Tools” extension. It’s this one: https://marketplace.visualstudio.com/items?itemName=ms-vscode.makefile-tools

Also, get the C/C++ extension pack:

https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack

Demo project

Download this Zip file, extract it, and open the folder with VSCode.

Note: When you have VSCode open and you click “Open Folder”, you’ll see your Linux system’s files, not the normal files of your computer. You can go to the directory /mnt/c to get to your files.

Take a look at the file named Makefile. This is a set of instructions that your computer will run in order to compile the project. The really cool thing here is that basically any computer that has make will run it the exact same way. This means that, when you submit your project, the only thing the TA has to do is run make , which will both ensure consistency and also make your TA happy 🙂. You can reuse this Makefile for other projects, but you will need to set the executable name (the line where it says PROG, change hello_world to the name of your project) and your source file names (where it says SRCS, list all of your C files).

Note that the Makefile has the recommended C flags to be used for this course. These ensure consistency with how the TAs compile it. If your code compiles with these C flags set, it should compile properly on a TA’s computer.

Using the Makefile tools extension

After installing Makefile tools, go to the “run and debug” section of the VSCode sidebar. You should see the category, MAKEFILE: PROJECT OUTLINE . To run your code, hover over this category and hit “play.” The output of the program will likely be in the “Terminal” section on the bottom bar.

You can also use the debugger by clicking the little bug icon next to the play button. The debugger will save your life in this course. See this page on how to use the debugger if it’s new to you — the only sections you really should care about are the “debug actions” and the “breakpoints” section.