How to compile C and Gtk+ with GCC on Linux?

前端 未结 5 1644
小蘑菇
小蘑菇 2020-12-31 20:12

I\'ve searched and searched but I\'m not getting the information I really want. Can someone please explain, as completely and fundamentally as possible, how Gtk+ code is com

5条回答
  •  醉话见心
    2020-12-31 20:34

    As others said, your question is overly broad. It asks about backticks (basic shell syntax), what ".o" files are (basic programming), and GTK programming (somewhat advanced programming).

    But to answer it best I can, and assuming you just have a single source file, use

    gcc -Wall -Wextra -std=c99 `pkg-config --cflags --libs gtk+-2.0` example.c -o example
    

    where "example.c" is the name of your source. Here's the breakdown:

    • Use the flags "-Wall" and "-Wextra" so you can see all the warnings (and fix them).

    • Use the "std" flag to set your C dialect. There are several and gcc has either total or partial support for most of them. Read the man pages or info pages for more information. Using "c99" like above is not a bad choice.

    • And use pkg-config and command substitution (i.e., backticks) to set the libraries and includes. Notice you can do both at once, although a lot of people use it twice by two backticked versions of pkg-config. Backticks substitute the output from the command within the ticks. Try running the pkg-config within the backquotes by itself on the command line and you'll see what it does.

    Unfortunately, there aren't many resources for 3.x GTK code and most of it is still 2.x based. You'll just have to resort to either gtk mailing lists or the reference manual.

    As for GTK 3.x, the reason you can't compile for it is likely that your distribution is GTK 2.x based. Newer distributions may have GTK 3.x in their repos.

提交回复
热议问题