Κεφαλίδες και σύνδεση

Αν και έχουμε εμφανίσει την εντολή μεταγλώττισης για το απλό παράδειγμα, θα πρέπει πραγματικά να χρησιμοποιήσετε τα εργαλεία automake και autoconf, όπως περιγράφονται στο "Autoconf, Automake, Libtool", από τον G. V. Vaughan κ.α. Τα χρησιμοποιούμενα παραδείγματα σε αυτό το βιβλίο περιλαμβάνονται στο πακέτο gtkmm-τεκμηρίωση, με κατάλληλα αρχεία δόμησης, έτσι δεν θα εμφανίσουμε τις εντολές δόμησης στο μέλλον. Θα χρειαστείτε απλά να βρείτε τον κατάλληλο κατάλογο και να πληκτρολογήσετε make.

Για απλοποίηση της μεταγλώττισης, χρησιμοποιούμε pkg-config, που είναι παρόν σε όλες τις (σωστά εγκατεστημένες εγκαταστάσεις) της gtkmm. Αυτό το πρόγραμμα 'ξέρει' τι διακόπτες μεταγλωττιστή απαιτούνται για μεταγλώττιση προγραμμάτων που χρησιμοποιούν τη gtkmm. Η επιλογή --cflags προκαλεί τη pkg-config να δώσει μια λίστα των περιλαμβανόμενων καταλόγων για να ψάξει ο μεταγλωττιστής· η επιλογή --libs ζητά τη λίστα των βιβλιοθηκών ώστε ο μεταγλωττιστής να συνδεθεί και οι κατάλογοι να τους βρουν. Δοκιμάστε να το εκτελέσετε από την προτροπή φλοιού για να δείτε τα αποτελέσματα στο σύστημά σας.

However, this is even simpler when using the PKG_CHECK_MODULES() macro in a standard configure.ac file with autoconf and automake. For instance:

PKG_CHECK_MODULES([MYAPP], [gtkmm-4.0 >= 4.8.0])
This checks for the presence of gtkmm and defines MYAPP_LIBS and MYAPP_CFLAGS for use in your Makefile.am files.

gtkmm-4.0 is the name of the current stable API. There are older APIs called gtkmm-2.4 and gtkmm-3.0 which install in parallel when they are available. There are several versions of gtkmm-2.4, such as gtkmm 2.10 and there are several versions of the gtkmm-3.0 API. Note that the API name does not change for every version because that would be an incompatible API and ABI break. There might be a future gtkmm-5.0 API which would install in parallel with gtkmm-4.0 without affecting existing applications.

Note that if you mention extra modules in addition to gtkmm-4.0, they should be separated by spaces, not commas.

The GNU site has more information about autoconf and automake.

If you start by experimenting with a small application that you plan to use just for yourself, it's easier to start with a Makefile similar to the Makefile.example files in the Building applications chapter.