Fatal error: glib.h: No such file or directory when using vscode and mingw

Viewed 3733

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.

enter image description here

Upon Ctrl-Shift-B to build, I get this.

enter image description here

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
            }
        }
    ]
}
1 Answers

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.

Related