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).
Related
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.
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"
}
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"
}
]
}
I'm getting the following fatal error while trying to include glib.h into a project. mingw gcc cant find glib.h.
fatal error: glib.h: No such file or directory
I've isolated the issue in a simple helloworld.c file.
Upon Ctrl-Shift-B to build, I get this.
I've also updated my includePath in my c_cpp_properties.json file per the instructions I read here.
Does anyone have any ideas of what I should look into or do to resolve this? I have spent many hours but not made any progress on this. :(
helloworld.c is:
#include <stdio.h>
#include <glib.h>
void main() {
printf("Hello World!");
char c = getchar();
}
c_cpp_properties.json is:
{
"configurations": [
{
"name": "MingGW",
"includePath": [
"${workspaceFolder}/**",
"C:\\cryptolibs\\msys2-64\\mingw64\\include\\glib-2.0",
"C:\\cryptolibs\\msys2-64\\mingw64\\lib\\glib-2.0\\include",
"C:\\cryptolibs\\pbc-0.5.14\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:\\MinGW\\bin\\g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceFolder}",
"C:\\cryptolibs\\msys2-64\\mingw64\\include\\glib-2.0",
"C:\\cryptolibs\\msys2-64\\mingw64\\lib\\glib-2.0\\include",
"C:\\cryptolibs\\pbc-0.5.14\\include"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
launch.json is:
{
// 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": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": ""
}
]
}
tasks.json is:
{
"tasks": [
{
"type": "shell",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": ["-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
To be able to use glib.h you need to have glib2 on your system.
If you have a shell (like MSYS2) normally you can get the compiler flags with:
pkg-config --cflags glib-2.0
and the linker flags with:
pkg-config --libs glib-2.0
On my MSYS2 system for example this returns:
-LD:/Prog/winlibs64-10.2.0/custombuilt/lib -lglib-2.0 -lintl
and
-mms-bitfields -ID:/Prog/winlibs64-10.2.0/custombuilt/include/glib-2.0 -ID:/Prog/winlibs64-10.2.0/custombuilt/lib/glib-2.0/include -ID:/Prog/winlibs64-10.2.0/custombuilt/include
respectively.
I'm trying to write a simple C program using VS code; there are 3 files in my program.
"main.c", "test.c", "test.h"
the "main.c" file is located in the workspace directory and "test.h" file is in the header folder and this folder is located in the workspace directory. I want to include "test.h" in "main.c" file but I get the following error:
"fatal error: test.h: No such file or directory".
I have searched a lot and try many solutions but I could not solve this problem. I will appreciate any kind of help.
this is "c_cpp_properties.json" file:
{
"configurations": [{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}\\header"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "8.1",
"compilerPath": "C:\\mingw\\mingw64\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}],
"version": 4
}
this is "task.json" file:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\mingw\\mingw64\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"${workspaceFolder}\\source\\test.c",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\mingw\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}