Working with Visual Studio Code
This section describes the basic setup for Visual Studio Code.

Correctly configured Visual Studio Code showing – among other things – left, debugging, testmate, and cmake pane selectors, and at the bottom, build type, kit, current target, and CTest runner.
Assumptions
For brevity, non-standard libraries are expected to be in the folder
./deps/thirdParty
.MSYS2/MinGW 64 Bit is used.
Installation
Install Visual Studio Code (https://code.visualstudio.com)
Install Extensions
Name |
Purpose |
---|---|
Support for C/C++, including IntelliSense and debugging |
|
Extended CMake support |
|
Run and debug GoogleTest |
|
|
Open the repository as folder, e.g. by calling
code simopenpass
after checking out. Say yes, when CMake Tools ask to configure the project. This creates abuild
folder, but fails (well, we need to config some stages).
Configuration
MSYS2 Path
Normally, runtime dependencies (DLLs) are not copied into the executables folder within the build process.
This means, that programs cannot be executed natively from Windows shells or the explorer.
It is therefore highly recommended, to set the environmental variable MSYSTEM=MINGW64
and CHERE_INVOKING=1
.
The setting of MSYSTEM
will cause the environment to be set up correctly for MinGW64.
Windows will then look for DLLs within the msys64 folders, allowing native execution.
CHERE_INVOKING
makes sure the shell stays in the current working directory.
As investigated recently, the C:\msys64\usr\bin``must also be added to the ``PATH
environment variable in order to resolve dependencies to cygpath.exe
.
Either set environment variable through the Windows PowerShell
# check if set
echo ${env:path}
echo ${env:MSYSTEM}
echo ${env:CHERE_INVOKING}
# if not
setx path "%PATH%;C:\msys64\usr\bin"
setx MSYSTEM "MINGW64"
setx CHERE_INVOKING "1"
or
Open the start search
Type in “env” and choose “Edit the system environment variables”
Choose “Environment Variables…”
Set the environment variables:
MSYSTEM=MINGW64
CHERE_INVOKING=1
Add
C:\msys64\usr\bin
to PATH
Visual Studio Code needs to be reloaded/restarted after the path update.
Note
An optimal solution would be to set the system environment variables in VSCode under settings.json
. This is currently not possible. Please contact us if you find a better solution.
IDEs, as Qt Creator, might set this variable base on the current build type on their own.
Build Kit
Add and select MSYS2/MinGW64 Build Kit:
Execute
Ctrl+Shift+P
:CMake: Edit User-Local CMake Kits
Insert/Update:
cmake-tools-kits.json1[ 2 { 3 "name": "MinGW64", 4 "preferredGenerator": { "name": "MinGW Makefiles" }, 5 "environmentVariables": { "PATH": "${command:mingw64.path}" }, 6 "compilers": { 7 "C": "${command:mingw64.cc.exe}", 8 "CXX": "${command:mingw64.cxx.exe}", 9 "Fortran": "${command:mingw64.fc.exe}" 10 }, 11 "keep": true 12 } 13]
Ctrl+Shift+P
:CMake: Select a Kit
=MinGW64
Select System Build Kit:
Ctrl+Shift+P
: CMake: Select a Kit
= GCC 10.2.0
See also Installing Prerequisites.
User Settings
Execute
Ctrl+Shift+P
:Preferences Open Workspace Settings (JSON)
Insert/Update:
settings.json1{ 2 // 3 // CMAKE 4 // 5 // Following settings are from the MSYS2 extension documentation 6 "cmake.cmakePath": "${command:cmake.buildkit.cmake.exe}", 7 "cmake.preferredGenerators": ["Unix Makefiles"], 8 "cmake.configureSettings": { 9 "CMAKE_MAKE_PROGRAM": "${command:cmake.buildkit.generator.exe}", 10 "CMAKE_VERBOSE_MAKEFILE": false 11 }, 12 // Optional: Adjust to your needs 13 "cmake.parallelJobs": 4, 14 // See openPASS documentation for individual WITH_* settings 15 "cmake.configureArgs": [ 16 "-DCMAKE_INSTALL_PREFIX=C:\\OpenPASS\\bin\\core", 17 // Adjust paths depending on your system 18 "-DCMAKE_PREFIX_PATH=${workspaceRoot}/deps/thirdParty/win64/FMILibrary;${workspaceRoot}/deps/thirdParty/win64/osi;${workspaceRoot}/deps/thirdParty/win64/minizip;${command:mingw64.root};${command:mingw64.root}/bin;${command:mingw64.root}/lib", 19 "-DUSE_CCACHE=ON", 20 "-DCMAKE_BUILD_TYPE=Debug", 21 "-DWITH_GUI=OFF", 22 "-DWITH_SIMCORE=ON", 23 "-DWITH_TESTS=ON", 24 "-DWITH_DOC=OFF", 25 "-DWITH_DEBUG_POSTFIX=OFF", 26 "-DINSTALL_SYSTEM_RUNTIME_DEPS=OFF", 27 "-DINSTALL_EXTRA_RUNTIME_DEPS=ON", 28 // For integration with IntelliSense (see c_cpp_properties.json) 29 "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" 30 ], 31 // 32 // TESTMATE 33 // 34 // Optional: Adjust to your needs 35 "testMate.cpp.test.parallelExecutionLimit": 4, 36 "testMate.cpp.test.parallelExecutionOfExecutableLimit": 2, 37 // Optional: Set, if you like to debug test discovery and test start issues 38 "testMate.cpp.log.logfile": "C:\\temp\\cpp.testmate.log", 39 // Optional: As CTest triggers the install step, dependencies between test executables 40 // and openpass libraries can be resolved by linking text executables to 41 // openpass install directory 42 // Alternative: Check dependencies of test executables by 'ldd <_Tests.exe> and copy 43 // libraries right next to test executable within build direcory 44 "testMate.cpp.test.advancedExecutables": [ 45 { 46 "pattern": "build/**/*{tests,Tests,TESTS}*", 47 "env": { 48 "Path": "C:\\msys64\\mingw64\\bin;C:\\OpenPASS\\bin\\core;C:\\OpenPASS\\bin\\core\\lib;${os_env:PATH};${workspaceFolder}\\deps\\thirdParty\\win64\\FMILibrary\\lib;${workspaceFolder}\\deps\\thirdParty\\win64\\osi\\lib\\osi3" 49 } 50 } 51 ], 52 // 53 // VSCODE 54 // 55 // Optional: Integration of MinGW64 Terminal in VS Code 56 "terminal.integrated.profiles.windows": { 57 "MinGW64": { 58 "overrideName": true, 59 "path": [ 60 "C:\\msys64\\usr\\bin\\bash.exe" 61 ], 62 "args": ["--login", "-i"], 63 "icon": "terminal-bash", 64 "env": { 65 "MSYSTEM": "MINGW64", 66 "CHERE_INVOKING": "1", 67 "MSYS2_PATH_TYPE": "inherit" 68 } 69 } 70 }, 71 "terminal.integrated.defaultProfile.windows": "MinGW64", 72 // Enforce usage of .clang-format of modified code 73 "editor.formatOnSave": true, 74 "editor.formatOnSaveMode": "modifications" 75}
settings.json1{ 2 // 3 // CMAKE 4 // 5 // Optional: Adjust to your needs 6 "cmake.parallelJobs": 4, 7 // See openPASS documentation for individual WITH_* settings 8 "cmake.configureArgs": [ 9 "-DCMAKE_INSTALL_PREFIX=/openPASS/bin/core", 10 // Adjust paths depending on your system 11 "-DCMAKE_PREFIX_PATH=${workspaceRoot}/deps/thirdParty/linux64/FMILibrary;${workspaceRoot}/deps/thirdParty/linux64/osi;${workspaceRoot}/deps/thirdParty/linux64/minizip", 12 "-DUSE_CCACHE=ON", 13 "-DWITH_GUI=OFF", 14 "-DWITH_SIMCORE=ON", 15 "-DWITH_TESTS=ON", 16 "-DWITH_DOC=OFF", 17 // For integration with IntelliSense (see c_cpp_properties.json) 18 "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" 19 ], 20 // 21 // TESTMATE 22 // 23 // Optional: Adjust to your needs 24 "testMate.cpp.test.parallelExecutionLimit": 4, 25 "testMate.cpp.test.parallelExecutionOfExecutableLimit": 2, 26 // Optional: Set, if you like to debug test discovery and test start issues 27 "testMate.cpp.log.logfile": "/tmp/cpp.testmate.log", 28 // 29 // VSCODE 30 // 31 // Enforce usage of .clang-format of modified code 32 "editor.formatOnSave": true, 33 "editor.formatOnSaveMode": "modifications" 34}
C++ and IntelliSense
Execute
Ctrl+Shift+P
:C/C++: Edit Configurations (JSON)
- c_cpp_properties.json
1{ 2 "configurations": [ 3 { 4 "name": "simopenpass", 5 "cStandard": "c99", 6 "cppStandard": "c++17", 7 "configurationProvider": "ms-vscode.cmake-tools", 8 "compileCommands": "${workspaceFolder}/build/compile_commands.json", 9 "intelliSenseMode": "linux-gcc-x64" 10 } 11 ], 12 "version": 4 13}
Configure the Build
Execute Ctrl+Shift+P
: CMake: Configure
CMake should now be able to configure the project. If not, cmake should give you at least a hint, what’s missing (normally external libraries). Read CMake Variables and Options or Installing Prerequisites for more information.
CMake
Some changes such as changing the build type (Debug/Release) will cause CMake to updates the configuration automatically.
Other changes won’t trigger an update, such as changing the paths to libraries (CMAKE_PREFIX_PATH), the cmake cache needs to be cleared before reconfiguration:
Ctrl+Shift+P
> CMake: Delete Cache and Reconfigure
Debug Targets
CMake Tools and C++ Testmate automatically use custom launch configurations, if available.
When using the debugging functionality, the according executable will be executed from where they are built (per default inside the build
folder).
This is acceptable for unit test, which do not require openPASS specific libraries. The corresponding config is
CMake Target
.For the core, located at
./build/sim/src/core/opSimulation/opSimulation
, this does not work, as no libraries and no configurations are available. As a solution, a second debug targetopsimulation
points at the installed executable instead.Warning
Don’t forget to run the target
install
before debugging .
Got to “Run and Debug” (
Ctrl+Shift+D
) and create a launch.json file.Insert/Update:
1{
2 "version": "0.2.0",
3 "configurations": [
4 {
5 // FOR TESTMATE (SELECTED TEST) AND CMAKE (DEBUG CMAKE TARGET)
6 "name": "CMake Target",
7 "type": "cppdbg",
8 "request": "launch",
9 "program": "${command:cmake.launchTargetPath}",
10 "args": [],
11 "stopAtEntry": false,
12 "cwd": "${workspaceFolder}",
13 "environment": [
14 {
15 "name": "PATH",
16 "value": "$PATH:${command:msys2.root}\\bin;${command:mingw64.root}\\x86_64-w64-mingw32\\lib${command:cmake.buildkit.launch.path}"
17 }
18 ],
19 "externalConsole": false,
20 "MIMode": "gdb",
21 "miDebuggerPath": "${command:cmake.buildkit.gdb.exe}",
22 "setupCommands": [
23 {
24 "description": "Enable pretty-printing for gdb",
25 "text": "-enable-pretty-printing",
26 "ignoreFailures": true
27 }
28 ]
29 },
30 {
31 // FOR DEBUGGING opSimulation (DON'T FORGET TO CALL make install)
32 "name": "opsimulation",
33 "type": "cppdbg",
34 "request": "launch",
35 "program": "C:\\OpenPASS\\bin\\core\\opSimulation.exe",
36 "args": [],
37 "stopAtEntry": false,
38 "cwd": "C:\\OpenPASS\\bin\\core",
39 "environment": [
40 {
41 "name": "PATH",
42 "value": "$PATH:${command:msys2.root}\\bin;${command:mingw64.root}\\x86_64-w64-mingw32\\lib${command:cmake.buildkit.launch.path}"
43 }
44 ],
45 "externalConsole": false,
46 "MIMode": "gdb",
47 "miDebuggerPath": "${command:cmake.buildkit.gdb.exe}",
48 "setupCommands": [
49 {
50 "description": "Enable pretty-printing for gdb",
51 "text": "-enable-pretty-printing",
52 "ignoreFailures": true
53 }
54 ]
55 }
56 ]
57}
1{
2 "version": "0.2.0",
3 "configurations": [
4 {
5 // FOR TESTMATE (SELECTED TEST) AND CMAKE (DEBUG CMAKE TARGET)
6 "name": "CMake Target",
7 "type": "cppdbg",
8 "request": "launch",
9 "program": "${command:cmake.launchTargetPath}",
10 "args": [],
11 "stopAtEntry": false,
12 "cwd": "${workspaceFolder}",
13 "externalConsole": false,
14 "MIMode": "gdb",
15 "setupCommands": [
16 {
17 "description": "Enable pretty-printing for gdb",
18 "text": "-enable-pretty-printing",
19 "ignoreFailures": true
20 }
21 ]
22 },
23 {
24 // FOR DEBUGGING opSimulation (DON'T FORGET TO CALL make install)
25 "name": "opsimulation",
26 "type": "cppdbg",
27 "request": "launch",
28 "program": "/openPASS/bin/core/opSimulation",
29 "args": [],
30 "stopAtEntry": false,
31 "cwd": "/openPASS/bin/core/",
32 "externalConsole": false,
33 "MIMode": "gdb",
34 "setupCommands": [
35 {
36 "description": "Enable pretty-printing for gdb",
37 "text": "-enable-pretty-printing",
38 "ignoreFailures": true
39 }
40 ]
41 }
42 ]
43}
Note
IntelliSense uses the compile_commands.json
of generated through CMAKE_EXPORT_COMPILE_COMMANDS=ON
(see settings.json
).
This is necessary for proper resolution of the include files.
Troubleshooting
Program does not start
The most effective way to debug startup issues is by means of the Process Monitor.
But normally, its a missing DLL. When executing the program via command line or explorer a message box should prompt which DLLs are missing.
A simple solution is to copy the according DLLs into the folder of the executable.
Another solution is to make the path available by extending the PATH
environment variable.
Potential sources for missing DLLs are C:\msys64\mingw64\bin
, C:\msys64\mingw64\x86_64-w64-mingw32\lib
, and the build
folder itself.
Tests are not listed
For test discovery, C++ Testmate needs to know the location of all additional dependencies. This information is retrieved from the current debug configuration.
Testmate discovers tests only after they are built. It pays to
Run CTest
to build all test targets. After this, you should see all tests in the testing pane on the left.Still not listed? Set
testMate.cpp.log.logfile
insettings.json
and check log.Test executable not mentioned at all: Executable name might not fit (check glob pattern in
testMate.cpp.test.executables
).Log reports Error: Not a supported test executable: a library/DLL might be missing.