Search code examples
cgccmingwglibmsys2

Msys2 and Mingw64 system include directory is incorrect preventing the use of GLib


I am doing C development on windows and installed Msys2. With Msys2 pacman I installed 64 bit mingw and Glib. I can use the gcc that was installed to compile. The Glib headers is now at C:\msys64\mingw64\include\glib-2.0 and C:\msys64\usr\include\glib-2.0.

When adding #include <gmodule.h> to a source file and compiling I get: fatal error: gmodule.h: No such file or directory

Checking the include paths with gcc -xc -E -v - I see errors:

Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-w64-mingw32
Configured with: ../gcc-8.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 -
-host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include
--libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=ada,c,lto,c++,objc,obj-c++,fortran --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev1, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 8.2.0 (Rev1, Built by MSYS2 project)
COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/cc1.exe -E -quiet -v -iprefix C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/ -D_REENTRANT - -mtune=generic -march=x86-64
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gc/x86_64-w64-mingw32/8.2.0/include"
ignoring nonexistent directory "F:/msys64/mingw64/include"
ignoring nonexistent directory "/mingw64/include"
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.2.0/include-fixed"
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/include"
ignoring nonexistent directory "F:/msys64/mingw64/x86_64-w64-mingw32/include"
#include "..." search starts here:
#include <...> search starts here:
 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/include
 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../include
 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/include-fixed
 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/include
End of search list.

How do I fix include paths so that gcc can find the GLib headers? I could add it to a spec file or C_INCLUDE_PATH but I it bypasses the error instead of fixing it.


Solution

  • If you install pkg-config, you can use it to obtain the build flags for glib, like this:

    $ pkg-config --cflags glib-2.0
    -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
    $ pkg-config --libs glib-2.0       
    $ -lglib-2.0
    

    The flags will vary from system to system, but the library name (glib-2.0) is hopefully consistent.