How to use Visual Studio Code in CSIL
Overview
There are many ways to write, compile, and debug your C/C++ code. One popular option is to use an IDE (Integrated Development Environment) which allows you to do all of those in one single program.
This page describes how to use the Visual Studio Code IDE (we will call it VS Code for short in this document). We selected VS Code because it is cross-platform (can be installed on many OSes like Linux, macOS and Windows), free and open-source. VS Code is installed on all of CSIL machines (under both Linux and Windows).
While there are many ways to use VS Code depending on where you are and how you are going to compile your code, this page explains a few of them.
Although the VS Code is designed for personal use, our course instructors and helpdesk have found ways to utilize VS Code in CSIL environment. Here they are:
- you could come to CSIL in person and use VS Code on any workstation
- you could use VS Code within CSIL VDI
- you could install VS Code on your own laptop and use SSH connection to a CSIL Linux system for compiling/debugging
Method 2 - use VS Code within CSIL VDI
To know more about CSIL VDI, please check out this how-to page.
Now, please perform all the following steps from within a web browser window.
Firstly, login to CSIL VDI using a web browser.
Here are the details:
1. Ensure you have your SFU Computing ID, OTP (SFU MFA) at hand and a stable internet connection in North America region.
2. Launch a new browser window, browse to our secrete Web Portal - please bookmark its URL.
3. Authenticate to this web site using your SFU Computing ID with password and the OTP from your SFU MFA device.
4. Now, log in to VMWare Horizon using your SFU Computing ID in the format of
username@sfu.ca
5. Click "SCS-Ubuntu" in the VMWare Horizon Client window, login using your username
Now, you will see the familiar CSIL Ubuntu environment.
Secondly, launch VS Code in the VDI session
Please click the applications menu in the lower left-hand corner, and search for "Visual Studio Code" in the search bar to bring up the application.
Thirdly, install the C/C++ extension (as needed)
To program C/C++ in VS Code, it is required to install the extension every time
you use the VDI service – this will only take a minute or two.
Click the "Extension" icon and search for "C/C++". Install
the extension "C/C++ InterliSense, debugg... from Microsoft"
Then, set SFU Home to store your project files
In VS Code, from the "File" menu, select "Open folder...", select "sfuhome" in right pane, then click "Open".
Please note: you must save all your files here (sfuhome) for them to be saved on the network. Please create sub-folders under it for your course work as needed.
when you move cursor over the "SFUHOME", a few buttons appear - you can use them to create new files/folders:
Finally, start programming
From here, you should be able to create, edit, compile & debug your C/C++ code.
To test the environment, please use the "Using GCC" instructions
on this
external link, starting at the "Create a Hello World App" step
(GCC and GDB come pre-installed on the CSIL VDI system).
Please do logout from CSIL VDI when you finish up for the day. Thank you!
Before we begin
This section is reproduced from CMPT 125 notes with permission from Dr. Victor Cheung - the original author of the notes.
Overview of this method
Install VS Code on personal computer; use this VS Code to establish SSH connection to a CSIL Linux system in order to use the CSIL's own gcc compiler in terminal.
We recommend this way because it allows you to work from anywhere (as long as you have a stable internet connection) and to check your code using the same compiler your course will use to compile your code during grading. If you are not 100% sure about which compiler to use, please ask the course instructor.
Here is a detailed walkthrough on how to accomplish this.
1: Install the free version of FortiClient VPN on your computer
Follow the steps on SFU VPN page, download, install and configure the free version of FortiClient VPN on your computer.
This is to allow your computer to connect to any SFU machines, including CSIL machines, when you are not on campus (i.e., not connected to SFU's WiFi).
2: Install VS Code on your computer
Browse to https://code.visualstudio.com and download the installer for your computer. Then install VS Code.
3: Install the "Remote - SSH" extension for your VS Code
In your VS Code, install the "Remote - SSH" extension. This is to allow your VS Code to connect to the CSIL machines via SSH. You only need to do it once.
Please note: this extension assumes you have a SSH client installed in your computer.
If you are using Linux, macOS and Windows 10 or newer, you probably already have it on the computer. Click here for details.
3.a. Special notes on your Windows 10/11 computer:
To check if you already have OpenSSH Client:
launch the Settings app,
then Navigate to "Apps & features" setting.
once there, click "Optional features" and search for "OpenSSH" in the installed features list as these two pages show.
If you see OpenSSH Client is installed, then you are good to go. Otherwise click Add a feature to install it.
Now, you should see the Remote SSH extension is installed and the Remote Explorer button appears on Activity Bar as this screenshot shows:
Step 1: (do this if you are off-campus, otherwise skip to Step 2):
Launch FortiClient VPN client and connect your computer to SFU VPN.
Step 2: Connect to a CSIL machine from your VS Code
In VS Code, you will see "Remote Explorer" view icon on the Activity Bar - a small green button at the bottom left with an icon that looks like >< on top of each other (only when the "Remote - SSH" extension is successfully installed),
Click this button and you will be prompted to "Select an option to open a Remote Window" at the top.
Choose "Connect to Host..." and then "Add New SSH Host...". Type this:
ssh -p24 your_sfu_computing_id@csil_host.csil.sfu.ca
where your_sfu_computing_id is your SFU Computing ID, and csil_host is one of the CSIL hosts listed in:
It is recommended to use one of the CSIL Linux CPU servers.
After pressing enter,
you will be asked to "Select SSH configuration file to update", pick the first one.
This is a file to keep a record of all the SSH hosts you have connected to; so next time you could just pick one from the list.
then choose "Connect" at the pop-up at the lower-right corner.
A new VS Code window will show up telling you that it is connecting and setting up the host (the CSIL machine you are connecting to). Keep an eye on it as it will ask for your SFU password to authenticate yourself.
Step 3: Install the C/C++ extension (if needed)
Once VS Code is connected (you'll see the green button at the lower-left corner showing the name of the CSIL machine), check if the "C/C++" extension has been installed (chances are you will only have to do it once).
If it is not in place, please install the "C/C++" extension. This is to allow Intellisense to work; and more importantly for you to build/compile/debug your code on the remote machine.
Step 4: Work on your code, build it, and debug it
This step is the same as how you would normally use VS Code (open/create folder, create new file, ... etc.), except now everything happens on the CSIL machine.
To build your code (actually you are building your program using your code),
at the top menu bar, go to Terminal > Run Build Task...
The first time you do this VS Code might ask you to choose an option.
Look for one that ends with /bin/gcc.
If the build task is successful, you'll see some information showing up at the bottom (the integrated terminal). Follow the instruction to press any key to close it.
A build task is just one way to compile and build your program. You will learn more ways in the class on handling multiple files and the use of a makefile.
At the same terminal area type ./ and then the name of the executable you just built. You should see the output from your program.
Repeat the build and run process each time you make changes to the code and want to test/debug it.
Step 5: Disconnect VS Code from the CSIL computer
In VS Code, choose File -> Close Remote Connection to disconnect from the CSIL computer.
Or you can simply exit VS Code to close the remote connection.
Since all CSIL resources are shared, it is highly recommended to disconnect from CSIL computer once you finish up for the day. Thank you!
Method 4 - use VS Code only on your own computer
As Microsoft has designed/marketed VS Code for personal use from the beginning, some people use VS Code on their own computers without utilizing CSIL infrastructure. We (the helpdesk) do not recommend this way.
Warning: when this method is used, all the codes you have are stored locally on your own computer. Please be sure to have backup regularly.
Here are a few how-to guides from the official Visual Studio Code docs.
for C/C++ programming,
Using GCC with MinGW on a Windows computer
Using Clang in Visual Studio Code on an Apple computer
A few more recommendations and reminders
1. Please remember, when you use the method 2 or 3 we recommended here, all your code and data are on CSIL storage.
So, you should always create your projects under folder "~/sfuhome" (which is your SFU Home).
If you want to have a local copy of your source files and projects, please use an SCP tool (e.g. Filezilla) to get them onto your own laptop.
2. We recommend the CSIL Linux CPU servers for remote use, simply because they are always available.
3. To use the Build Task function in VS Code, please modify the task.json file to include all the necessary .c files in the args field.
For more details on Tasks in VS Code, please read this official guide.
4. The "Makefile Tools" extension is still in Preview (as of Spring 2024), so use it with extra caution.
5. In this document, we only scratched the surface of C/C++ support in VS Code. When you are ready to explore beyond C/C++, please be sure to check out this external page - VS Code supports a great number of programming languages.
Resources:
- https://code.visualstudio.com/docs/cpp/introvideos-cpp talks about using VS Code for C/C++. It says for C++ but most of the content works for C as well.
- https://code.visualstudio.com/docs/remote/ssh talks about what VS Code is doing when it is using SSH. You don't have to know everything described there. But please read the sections "Connect to a remote host" and "Disconnect from a remote host".
- https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse?tabs=gui talks about the SSH client on Windows. You only need the client for things to work.
- https://code.visualstudio.com/Docs/editor/debugging talks about how to debug your code in VS Code. Please read through the page to find the most suitable debugging methods for you.
Visual Studio Code on my laptop suddenly cannot SSH to CSIL, what I can do?
The common cause of this issue is: certain extensions, settings etc. of VS Code on CSIL system become corrupted.
Please try the following steps to resolve this issue:
Firstly: Check whether you could SSH in to CSIL directly (without using VS Code).
SSH into a CSIL CPU Server using a modern SSH client like MobaXterm / PuTTY / PowerShell - be sure you are connected to SFU VPN.
. please try a few if one CSIL CPU Server fails
. you may want to reboot your own laptop first
if you cannot SSH into any of the CSIL CPU Servers by using an SSH client, contact helpdesk asap.
Proceed to the next step if you were able to SSH in to a CSIL CPU Server.
Secondly: Clean up the crucial VS Code folder on CSIL system
While login to a CSIL CPU Server, run the following commands in the Terminal window:
cd ~/.vscode-server; rm -rf *
(This will remove everything under folder ~/.vscode-server )
Now on your laptop, try SSH into this CSIL CPU Server using VS Code.
In most cases, this should work now. Done.
If it is still unsuccessful, proceed to next step.
Finally: Re-install VS Code on your laptop
- uninstall currently installed VS Code.
- then install latest stable version of VS Code.
- install Remote-SSH extension as described on this very page.
- now, try again: SSH into a CSIL CPU Server within newly installed VS Code.
If this works, please install the additional extensions you need. Done.
If VS Code still cannot SSH into a CSIL CPU server, please email us asap.
Visual Studio Code on my laptop gets timeout error while SSH to CSIL, what I can do?
Before tackling this issue, please check SSH configuration first:
From your laptop, test the SSH connection directly (with the SFU VPN connection established while off-campus) - not using Visual Studio Code.
- If the SSH connection fails, please email helpdesk.
While direct SSH connection to CSIL is successful, there could be a timeout or connection issue within VS Code’s SSH extension itself. Here are 2 methods you could try:
The first method: configure a longer SSH timeout setting in VS Code:
Open VS Code settings
Search for Remote.SSH: Connect Timeout and increase the value (default is 15 seconds, try 120 seconds)
The second method: Reinstall the Remote-SSH extension (SSH extension may stop working properly):
Open the Extensions view in VS Code (key combo: Ctrl + Shift + X)
Search for Remote - SSH and uninstall/reinstall the extension.