VS Code Customizing Command Argument - c

I have been trying to customize the argument command for compiling the c file in vs code but I could not figure it out.
I would like to get warnings with -Wall and use the C99 standard with -std=c99 and I wanted to customize my argument like:
gcc -Wall -std=c99 hello.c -o hello
I guess I should add the argument in the tasks.json file but it is really confusing.
This is my tasks.json file.
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-Wall",
"std=c99",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

Related

Task with C run failed in vscode terminal

vscode version: 1.73.1
OS: windows 11
{
"tasks": [
{
"type": "cppbuild",
"label": "cbuild",
"command": "gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "c debug",
}
],
"version": "2.0.0"
}
this is my task file.
it did not work in vscode terminal.
> gcc -fdiagnostics-color=always -g D:\study\c-app\C-Primer-Plus-Answer\ten\seven.c -o D:\study\c-app\C-Primer-Plus-Answer\ten\seven.exe
> 'cmd' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
> The generation has been completed, but there is an error.
In the powershell, it work correctly.
I've tried in powershell, it worked.But, it failed in vscode terminal.I don't know what should i do.By the way,the messy code maybe is chinese.

match files .c on tasks.json to compile

i'm using the microsoft extension on vscode to compile C, the problem is, with one file .c, ok, but when i include some lib, like conio.c, i need to tell manually to compile this file too putting the name of the file in the tasks.json, i want to do this automatically, but i can't add any "pattern" in tasks.json, and i don't know if .json runs regex, thanks in advance! Basically i want to match all .c that i'm using in the main program.
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe arquivo de build ativo",
"command": "gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}" ---add name of file to here compile---,
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Tarefa gerada pelo Depurador."
}
],
"version": "2.0.0"
}
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe arquivo de build ativo",
"command": "gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${fileDirname}\\**.c",
"${fileDirname}\\**.h",
"-o",
"${fileDirname}\\bin\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Tarefa gerada pelo Depurador."
}
],
"version": "2.0.0"
}

tasks.json In VS Code

I am trying to debug a C program in VS Code. When I run my program from the command line it works because I can add pthread to the args by typing: gcc -pthread -o Draft1 Draft1.c. However, when I try to run it in vs code it doesn't work because the tasks doesn't add "-pthread" to it. I try to add it to the args in the tasks.json file but it doesn't seem to do anything. What am I missing? Here is my tasks.json file:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: arm-none-eabi-gcc build active file",
"command": "/usr/bin/arm-none-eabi-gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-pthread",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/arm-none-eabi-gcc"
}
]
}

Visual Studio Code Include path

How do I include commands for gcc in VS Code? The project compiles without any error if i type the following command in the terminal gcc main.c pkg-config --cflags --libs gtk + -3.0 -export-dynamic. But I have no idea how to configure this in VS Code.
I tried to include everything in c_cpp_properties.json without any luck.
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/gtk-3.0",
"/usr/include/glib-2.0"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
"-Wall",
"-Wextra",
"-Wpedantic",
"pkg-config --cflags --libs gtk+-3.0`",
"-export-dynamic"
],
"defines": [
""
]
}
],
"version": 4
}
Problem solved!
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"`pkg-config",
"--cflags",
"--libs",
"gtk+-3.0`",
"-export-dynamic"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Any tips on how to get rid of the following error message?
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/home/malte/Projects/GtkButton/main/src/main.c).

Adding a C external library in Visual Studio Code

How can I add an external C library in Visual Studio Code?
I read How can I include a needed C library using GCC? and tried:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "build",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-L \\C:\\MinGW\\lib",
"-l libws2_32.a"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
]
}
]
But I got
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -l libws2_32.a
collect2.exe: error: ld returned 1 exit status
And I installed GCC in folder C:\MinGW.

Resources