How to use VSCode for writing compiler commands
![Complier Commands](/Compiler_Commands_VScode.gif)
Simplify writing compiler commands
Motivation
While learning C/C++ I found that writing the compiler commands for the terminal is tedious job especially if you write many files. To simplify this process you can use the snippets of vscode.
Solution
The steps are as follows:
- Open the command palette
- Enter
Configure User Snippet
- Select the language for which you would like to configure your the snippets, I choose
C
- A
.json
File will open and you can configure your snippets for allC
programms - For writing the compiler commands I use the following snippet:
"compile_pthread": {
"prefix": "comp",
"body": [
"$LINE_COMMENT gcc -o $TM_FILENAME_BASE -lpthread $TM_FILENAME && ./$TM_FILENAME_BASE ",
],
"description": "Create compiler commands"
}
With the prefix comp
I can write the compiler command for a specific c file. With the variable $LINE_COMMENT
I create a line comment, $TM_FILENAME_BASE
takes the file name and $TM_FILENAME
is the full file name e.g. programm.c
. I included the -lpthread
option as I currently study parallel programming.