Search code examples
linuxcompiler-errorsshared-librariesglib

Error when compiling with "gcc $(pkg-config --cflags --libs glib-2.0) context.c" -> <galloca.h> not found


I tried to compile my context.c file with "gcc $(pkg-config --cflags --libs glib-2.0)" context.c.

But it doesn't work because it does not find galloca header file:

context.c:3:10: fatal error: galloca.h: file or directory not found #include <galloca.h>

I tried "gcc $(pkg-config --cflags --libs glib-2.0 glib)" where galloca.h is located /usr/include/glib-2.0/glib. But after adding glib to the compile command, it does not even find glib.h anymore, which is in /usr/include/glib-2.0.

I tried to add the all necessary paths to PKG_CONFIG_PATH with "export PKG_CONFIG_PATH=/usr/include/glib-2.0/gio/pkgconfig" and so on.... without success.

I also added all necessary library paths to /etc/ld.so.conf and sudo ldconfig -v, also without success.

It is not the first time i face the problem, that necessary libraries can't be found on this system while compiling, but as we in germany say: "i am at the end of my latin", so i have no more clue how to solve this issue and would be gratfull for any help.

Thanks in advance.

PS: I use a raspberry pi 4B 8GB and raspbian linux.


Solution

  • Your library path will not help it to find include file.

    Maybe you want -I/usr/include/glib-2.0 -I/usr/include/glib-2.0/glib

    Maybe your build script accept CFLAGS environment variable where you can put this option.

    Or maybe you change (edit) source code,

    #include <galloca.h>
    

    become

    #include <glib/galloca.h>
    

    because already it looks correctly in /usr/include/glib-2.0, only the subdirectory is wrong

    Afterwards you discover if you must set some path also for libraries. But one thing by one, first compile, then worry about the link. You talk about ld.so.conf. Really this is for runtime, but OK, at build it is last option after trying everything else (see at man ld and search ld.so.conf). Really for build time library path you want -L option maybe with LDFLAGS environment variable. But as I say, first try compile and then discover if link problem.

    Wer mit seinem Latein am Ende ist, muss Griechisch sprechen.