match files .c on tasks.json to compile - c

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"
}

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.

Problem compilate with gcc & gdb on Vs code with windows

I’m starting with VScode and I can’t compile my programe corectement in C.
I’ve done a lot of research and I can’t find a solution. Can anyone help me?
C_CPP_Properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\MinGW\\include",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
Launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Lancer",
"type": "cppdbg",
"request": "launch",
"program": "C:\\MinGW\\bin\\gcc.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Activer l'impression en mode Pretty pour gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Settings.json
{
"files.associations": {
"time.h": "c"
}
}
Task.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe générer le fichier actif",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe "
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"isDefault": true,
"kind": "build"
}
}
]
}
Main.c
#include<stdio.h>
#include<stdlib.h>
int main() {
int i = 1;
printf("Hello World\n");
return 0;
}
Error
PS C:\Dev\.git\Code> The program 'C:\MinGW\bin\gcc.exe' has exited with code 1 (0x00000001).
I’d really like to make it work,
I tried to manage on my own but I really didn’t find anything.
I hope the code I put in will be enough to maider.
Thx and have a good day :)

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).

Get No such file or directory in Visual Studio Code when Debug with gcc

My C project need use MySQL, so there is code:
#include "mysql.h"
I just couldn't find out where should I add include path, or which key point I missed, I think I have get it done already. When I debug with (Windows)启动, it's works fine. But when I choose "gcc.exe", it always get "mysql.h: no such file or directory", please help!
I tried everything I can but still get this error.
this is my c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Program Files/MySQL/MySQL Server 8.0/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Program Files/mingw64/bin/gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
this is my launch.json:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
},
{
....................
},
]
}
this is my task.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\Program Files\\mingw64\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-I",
"C:/Program Files/MySQL/MySQL Server 8.0/include",
"-L",
"C:/Program Files/MySQL/MySQL Server 8.0/lib",
"-llibmysql",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\Program Files\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: \"C:\\Program Files\\mingw64\\bin\\gcc.exe\""
}
]
}
The first thing I would try is hiding those spaces in your paths; terminal will read them as the end of an argument and start of a new one.
For example, in your launch.json, you have
"options": {
"cwd": "C:\\Program Files\\mingw64\\bin"
},
which I would try editing to
"options": {
"cwd": "C:\\\"Program Files\"\\mingw64\\bin"
},
Currently, terminal sees the path "C:\Program" and interprets "Files\mingw64\bin" as some weird argument that it probably just ignores. Your windows debugger may be smart enough to figure out that's wrong, but terminal operates pretty literally.
With "Program Files" contained in quotes (with escape chars), terminal should be able to read the whole path. Try that everywhere you have spaces in your paths and see if it helps.

Resources