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

I searched and searched, but I do not get the information that I really want. Can someone explain, as far as possible, completely and fundamentally how to compile Gtk + code when writing to C using GCC in Linux. There are things like backticks, "c99" and .o files that I don’t understand at all.

I also appreciate any resources for learning Gtk + code. All the sources that I found relate to versions 2.x, but I think 3.6 is the current version.

I would like to repeat, I am only interested in the C code. Please do not try to explain to me the advantages of C ++ or C #, I read all of them. I am here for C. Thank you!

+5
source share
4 answers

-, C-, "hello_world_gtk.c", Gtk, . pkg-config. , :

pkg-config gtk+-2.0 --cflags

:

pkg-config gtk+-2.0 --libs

pkg-config gcc:

gcc `pkg-config gtk+-2.0 --cflags` hello_world_gtk.c -o hello_world_gtk `pkg-config gtk+-2.0 --libs`

. , .

Gtk 3 "2.0" "3.0". pkg-config , , Gtk, Linux.

, - , , Gtk, C. , Gtk.

+15

, . backticks ( ), ".o" ( ) GTK- ( ).

, , , , ,

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

"example.c" - . :

  • "-Wall" "-Wextra", ( ).

  • "std" C. , gcc . . "c99", , .

  • pkg-config (.. backticks) . , , backticked pkg-config. Backticks . pkg-config backquotes , , .

, 3.x GTK , - 2.x. gtk .

GTK 3.x, , , , GTK 2.x. GTK 3.x .

+2

Makefile:

LDLIBS = -lcurl -lpthread `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`
0

From the Gtk Docs Getting Started Document :

gcc `pkg-config --cflags gtk+-3.0` -o example example.c `pkg-config --libs gtk+-3.0`

Also check out Nikos C. Aswer to learn more about pkg-config.

0
source

All Articles