It is quite nice to use Visual Code as an IDE to build linux cpp projects in a WSL environment.
- Install WSL2 or WSL
2. Install VS code in Win 10 and install the neccessary plugins, including Remote WSL, C/C++, C++ Intellisense and Cmake.
3. In WSL, go to the director where you want to make a cpp project and open VS code in current folder by “code .” Then, a VS code window linked with WSL is opened.
4. Create a new cpp file in this folder.
5. Create a file named CMakeLists.txt.
6. From the main menu, choose “Terminal> Configure default build task”. In the dropdown, which will display a tasks dropdown listing various predefined build tasks for C++ compilers. Choose “g++ build active file”, which will build the file that is currently displayed (active) in the editor. Change the “tasks.jason”. Make a new folder named “Build”. With the “tasks.jason” file, it possible to build the project with cmake by press Ctrl+Shift+b.
7. From the main menu, choose “Run > Add configuration”. Choose “g++ build and debug active file”. Edit it to configure the debug setting. Then we can debug the project by pressing “F5”. If you do not want to stop before the first line is executed during debugging, you can change the setting from “”stopAtEntry”: true” to “”stopAtEntry”: false”.
8. It is also possible to configure a cmake project with the plugin “CMake Tools” by following “CMake-quick start” -> “CMake-Build” or “CMake-Debug”.