Why can't I build a “hello world” for glib?

前端 未结 5 1456
走了就别回头了
走了就别回头了 2021-01-30 13:26

So here\'s the world\'s simplest glib program:

#include 

I try to compile it with gcc test.c and I get:



        
5条回答
  •  粉色の甜心
    2021-01-30 13:30

    glib tends to hide itself... Your include statement doesn't work because GCC doesn't automatically search subdirectories, and so cannot see the glib.h in glib-1.2 or glib-2.0.

    Read the Compiling GLib Applications page in the GLIB manuals... you use commands like pkg-config --cflags glib-2.0 to get the right flags for GCC.

    The canonical way to do what you are trying is

    % gcc test.c -Wall -o test `pkg-config --cflags --libs glib-2.0`
    

    Note the back-ticks, which tell the shell to run the pkg-config command "in-place".

提交回复
热议问题