Recently I wanted to compile C + + code on Linux, but I was accustomed to the IDE on window. I used to use Eclipse + CDT when the company wanted me to write Linux code, and I personally felt that because the load component was too much, the opening was very slow, so I didn't want to use it. Later with a bit of Vim + CMake to do, compile is can, debugging and a little trouble. Today, when I visited Csdn, I read a post saying that Visual Studio code could compile and debug C + +, and I ran to the Microsoft Web site to find C + + for VS code, and I simply recorded the compilation process:
First, shortcut keys
1. Open the Command Palette (ctrl+shift+p)
2. Can now build your application with (ctrl+shift+b)
3, press (ctrl+shift+o), then enter the name of the symbol you ' re looking for
4. To search for a symbol in the current workspace,start by pressing (Crtl + T)
Second, install the compilation debugging process (I do not repeat the write)
1, the installation can be directly here to see, very simple: C + + for VS code, if you do not understand English, there is a buddy also write the basic process: http://blog.csdn.net/q932104843/article/details/51924900
Iii. Debugging third-party libraries, such as (Muduo library)
Since Vscode is compiled with GCC, it is very important to be familiar with GCC, if you are unfamiliar with GCC, you can refer to the GCC Technical Reference.
1. Follow this article to install the Muduo library
2. Use Vscod to open the Echo example directory, as follows:
2, configuration Launch.json, such as:
First click on the Debug button (red number 1), then click on the Configure button (red number 2), in the pop-up option choose: GDB.
Finally, change "Enter program name for example ${workspaceroot}/a.out" to "${workspaceroot}/a.out". (Red numbers 3 and 4)
3. Configure Tasks
First press the shortcut key: Ctrl + Shift +p, then enter: >tasks, then pop-up drop-down options: Tasks:configure Task Runner, such as:
OK, let's change the default Tasks.json to the following:
And why should it be changed? You can open the Echo directory with the terminal and enter:
g++-g-o a.out echo.cc main.cc-i/home/lh/downloads/build/debug-install/include/-l/home/lh/downloads/build/ debug-install/lib/-lmuduo_base-lmuduo_net-lpthread
You can see that the Echo directory has more a.out files. In fact, Vscode is also compiled with GCC commands, and its parameters (Red number 2) are basically the same as GCC parameters.
We can use the shortcut key directly: Ctrl + Shift +b to compile, you can see the echo directory is more than the A.out file.
4. Debug program
First set breakpoints (red number 2) such as:
Click the Debug button (red number 1), as
You can see the various local variables to prove that the debug was successful.
Use Visual Studio code under Ubuntu to compile and debug C + +