Remote C/C++ Debugging with VSCode #2 - VSCode Makefile Tools
This article is a continuation of the previous blog(https://tipspiggy.blogspot.com/2022/05/remote-cc-debugging-with-vscode-1.html).
Traditionally, Makefile is mainly used for Linux C/C++ development.(In fact, Makefile and make can be used not only in C/C++ but also in various development language projects.) The usual purpose for Makefile in C++ projects is to recompile and link necessary files based on the modifications done to dependencies.
Compared to development tools such as Visual Studio on Windows, the extension sln and vcxproj files are used. When developing C/C++ using Visual Studio on Windows, most of us do not look at the contents of sln (Visual Solution File) and vcxproj (Visual Studio Project File) files. The reason is that if you select the properties of a solution or project in Visual Studio IDE, you can easily see the contents of the file in the property window.
However, although the Linux system uses a desktop mode that supports a GUI, there are also many cases where a server mode that does not support a GUI is used. Therefore, many developers use a lot of Makefiles that can build C/C++ projects in the terminal.
In February 2021, Microsoft released the Makefile Tools extension that automatically generates Makefiles. We will use this tool to manage a Makefile file on a remote Linux computer and proceed with the build.
Installing the Makefile Tools extension
First, install the Makefile Tools extension from the VS Code Marketplace. Refer to the previous article "Remote C/C++ Debugging with VSCode #1 - Installation and simple debugging" and open the directory on the remote computer again.
Install the Makefile Tools extension on the remote Linux system.
Once the extension is installed, it will activate when it finds a Makefile in your project’s root folder. In the previous article, I made only one hello.cpp file and then built it with the "make -g hello.cpp" command, so the Makefile does not exist yet.
Make a sample Makefile and "Makefile Tools" configuration
Create and save the following simple Makefile.
# # A simple makefile for compiling a c++ project # TARGET=hello GCC = g++ CFLAGS = -g -o $(TARGET) RM = rm -rf all: clean default default: $(GCC) $(CFLAGS) hello.cpp clean: $(RM) $(TARGET) *.o
And run "Makefile: Configure" from the Command palette.
There will now be a Makefile button on the left slider bar.
Click the Makefile button on the slide bar to set the configuration as follows.
I made three rules in the Makefile: default, clean, and all.
Build target selects all or default. If you always want to rebuild, select all.
Now, if you press the build button at the top, the rules of the selected build target are executed.
Finally, set the Launch target.
Debugging
Debugging passing arguments to the executable program
#include <iostream> int main(int argc, const char * argv[]) { int a = 1; int b = 2; int c = a + b; std::cout << c << std::endl; if(argc > 1){ for(int x = 1; x < argc; x++){ std::cout << "parameter: " << argv[x] << std::endl; } } return 0; }
And add the following arguments to binaryArgs in settings.js. Now, when the run button is pressed, it asks whether to apply the arguments or not. If you select the option to use the second argument, the arguments are passed to the executable program.
댓글
댓글 쓰기