how gcc automatically know to include glib library

前端 未结 1 657
花落未央
花落未央 2021-01-25 11:32

I make simple program in C which uses glib.h, but when I compile it I get an error like:

$ gcc test.c -o test
test.c:3:18: fatal error: glib.h: No s         


        
相关标签:
1条回答
  • 2021-01-25 12:01

    No.

    The problem of looking at C source code and figuring out which libraries it uses is very hard. It feels kind of "AI complete" to me, which is why it's typically solved manually by the programmer pointing out the exact right libraries to satisfy the dependencies with.

    Just for glib, it's easy to imagine a system with both glib 1.x and 2.x versions installed, and some calls are named exactly the same. Now try to imagine a computer program capable of decucing what you meant, which library to link with. It's not possible, since only the programmer knows.

    The pkg-config tool helps with the mechanics of what each library requires in order to be used, but it's still up to yuo to tell it (via the module name argument(s)) which exact libraries to use.

    0 讨论(0)
提交回复
热议问题