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

前端 未结 5 1460
走了就别回头了
走了就别回头了 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:33

    > > The canonical way to do what you are trying is
    
    > % gcc test.c -Wall -o test `pkg-config --cflags --libs glib-2.0`
    

    Sorry, but no. That is a common misconception, that just happens to work in most cases on ELF-based systems, Linux in particular. The canonical way is to pass in the cflags and libraries separately, in the correct and traditional locations on the command line, like this:

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

    It is a pity that pkg-config accepts both the --cflags and --libs options at the same time, as it means this incorrect meme will never die, and people used to it on Linux will continue to be baffled when they then try the same on other platforms.

提交回复
热议问题