Visual Studio Code is a free source-code editor made by Microsoft for Windows, Linux and macOS. Features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git. C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++ development on Windows, Linux, and macOS. The Code Runner extension allows execution of single files. For project compilation, consisting of multiple files, the C/C++ Makefile Project extension can be used (and can be adapted for Fortran). Visual Code Studio can be downloaded from the website https://code.visualstudio.com/download. VS Code is first and foremost an editor, and relies on command-line tools to do much of the development workflow. There is basic support for html, css, javascript and typescript out of the baox. Support for other languages is supported via extensions. VS Code does not include a C/C++ or Fortran compiler or debugger. You will need to install these tools or use those already installed on your computer.
Table of Contents
Installing a C/C++/Fortran Compiler
On MacOS, first check if the compiler toolset is already present
gcc -v
which show the compiler version if the compiler is present, for example
% gcc -v
Apple clang version 16.0.0 (clang-1600.0.26.6)
If it is not present, then it will present an install panel. The installation can also be forced using
xcode-select --install
The Apple toolchain does not include a Fortran compiler. Using home-brew, it easy to install one. Homebrew can be installed using
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
and then installing the gcc package
brew install gcc
which include the ‘gfortran’ compiler. Optional: also install python3 for Fortran IntelliSense (python has a Fortran implementation of the Language Server Protocol).
brew install python3 fortls
On linux, for example Ubuntu-type systems, the compilers, and cmake and ninja can be installed using
sudo apt install build-essential gfortran cmake ninja
On windows, a compiler needs to be installed. MSYS2 is a collection of tools and libraries providing you with an easy-to-use build system. Download MSYS2 from https://www.msys2.org. Follow the installation instruction steps, including step 7 which installs the C/C++/gfortran compiler and build utilities like ‘make’.
(goto https://www.msys2.org)
(download the installer)
(run the installer)
(finish and a UCRT64 terminal environment will launch)
pacman -Syu
(reopen 'MSYS2 UCRT64' from the start menu)
pacman -Su
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
(just press enter for default)
pacman -S mingw-w64-ucrt-x86_64-gcc-fortran
pacman -S mingw-w64-ucrt-x86_64-cmake
pacman -S mingw-w64-ucrt-x86_64-ninja
pacman -S mingw-w64-ucrt-x86_64-python-pip mingw-w64-ucrt-x86_64-python-setuptools
/ucrt64/bin/pip3 install fortran-language-server
/ucrt64/bin/pip3 install fortls
pacman -S mingw-w64-ucrt-x86_64-lapack
pacman -S git unzip zsh vim
After step 5, the terminal will closed, and you need to reopen ‘MSYS2 UCRT64’ from the Start menu.
After step 8 and 10, you will have a fully functional build system and have access to ‘gcc’, ‘g++’, ‘gfortran’, and ‘make’ to build software. Step 11 and 12 install the ‘cmake’ and ‘ninja’ build utilities. Step 13-15 install the fortran language server. Step 16 and 17 show that the MSYS2 bash environment can be extended with a lot of packages. The installation of lapack allows the linking with ‘-llapack -lblas’ to solve for example eigenvalue problems. Git, unzip are useful utilities, and you could also for example change the default bash shell and use zsh (also used on mac).
Steps 8 and 9 install the fortran language server in python. There are two versions of python in MSYS2: (1) MSYS2 – POSIX applications emulated to work in Windows, and (2) MINGW – Windows native applications. We need the latter, since the IntelliSense in VS Code calls the fortran compiler (fortran.exe) and fortran language server (fortls.exe) from windows. MINGW refers to executables that are compiled using the MINGW GCC Compiler and target the Win32 API.
Install Visual Studio Code extensions
Launch Visual Studio Code. In the side bar (left), click the “Extensions” icon, and install the following extensions:
C/C++ Intellisense (Microsoft)
Modern Fortran (fortran-lang.org)
CMake Tools (Microsoft)
WSL (Microsoft)
Remote - SSH (Microsoft)

The C/C++ extension adds language support for C/C++ to Visual Studio Code, including features such as IntelliSense and debugging. The CMake extension provides us with a build-system. The Modern Fortran extension for VS Code provides support for syntax highlighting, IntelliSense, and debugging. The Remote – SSH and WSL extension are optional, but often used in this workflow.
Edit Visual Studio Code settings

For MacOS, modify the ‘settings.json’ file to
{
"cmake.debugConfig": {
"stopAtEntry": false,
"MIMode": "lldb",
"miDebuggerPath": "/Users/dubbelda/.vscode/extensions/ms-vscode.cpptools-1.22.11-darwin-x64/debugAdapters/lldb-mi/bin/lldb-mi",
"logging": {
"trace": true,
"engineLogging": true,
"traceResponse": true
}
}
}
Modify line 5 to point to your ‘lldb-mi’ executable in your .vscode folder.
For windows using MSYS2, modify the ‘settings.json’ file to
{
"workbench.colorTheme": "Default Light Modern",
"cmake.cmakePath": "C:\\msys64\\ucrt64\\bin\\cmake.exe",
"cmake.configureSettings": {
"CMAKE_AR": "C:\\msys64\\ucrt64\\bin\\ar.exe",
"CMAKE_MAKE_PROGRAM": "C:\\msys64\\usr\\bin\\make.exe",
"CMAKE_PREFIX_PATH": "C:\\msys64\\ucrt64"
},
"cmake.environment": {
"PATH": "C:\\msys64\\ucrt64\\bin;C:\\msys64\\usr\\bin;${env:PATH}"
},
"cmake.generator": "MSYS Makefiles",
"cmake.debugConfig": {
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\ucrt64\\bin\\gdb.exe"
},
"fortran.linter.compiler": "gfortran",
"fortran.linter.compilerPath": "C:\\msys64\\ucrt64\\bin\\gfortran.exe",
"fortran.fortls.path": "C:\\msys64\\ucrt64\\bin\\fortls.exe",
"terminal.integrated.profiles.windows": {
"MSYS2": {
"path": "C:\\msys64\\usr\\bin\\bash.exe",
"args": [
"--login",
"-i"
],
"env": {
"MSYSTEM": "UCRT64",
"CHERE_INVOKING": "1",
"PATH" : "/ucrt64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/"
}
}
},
"terminal.integrated.defaultProfile.windows": "MSYS2",
"terminal.integrated.env.windows":
{
"MSYSTEM": "UCRT64",
"CHERE_INVOKING":"1",
"PATH" : "/ucrt64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/"
},
"cmake.pinnedCommands": [
"workbench.action.tasks.configureTaskRunner",
"workbench.action.tasks.runTask"
]
}
and save the file. Also the fortran executable and the fortran language server are set to the ones of MSYS2.

For adding source-files, add them to ‘src’-folder and list them in the ‘CMakeList.txt’ in the ‘src’-folder.
Sources



