头文件和链接

虽然我们已经给出了这个简单的例子的编译命令,但是你最好还是使用 automake 和 autoconf 工具,就像 G. V. Vaughan 等在《Autoconf, Automake, Libtool》中所描述的那样。本书中用到的例子都包含在 gtkmm 包内,同时附有适当的编译构建的文件,所以我们以后不会再给出任何编译命令。你只需要找到恰当的目录然后键入 make

为了简化编译的过程,我们使用了 pkg-config,它存在于所有的(也许已经安装的) gtkmm 安装文件中。这个程序“知道”编译使用了 gtkmm 的程序所需要的编译器选项。--cflags 选项使 pkg-config 输出一个包含编译时需要用到的头文件的目录列表;而使用 --libs 选项将得到一个需要编译器去链接的库列表和一个用于寻找它们的目录列表。试着在你的命令行提示符下运行它,看看在你的系统上会有什么样的结果。

然而,在标准的 configure.ac 中使用 PKG_CHECK_MODULES() 宏,并且运行 autoconf 和 automake 后,这变的更加简单。例如:

PKG_CHECK_MODULES([MYAPP], [gtkmm-3.0 >= 3.0.0])
这将会检查是否存在 gtkmm,并且定义了可以在你的 Makefile.am 文件中使用的 MYAPP_LIBS 和 MYAPP_CFLAGS 变量。

gtkmm-3.0 is the name of the current stable API. There was an older API called gtkmm-2-4 which installs in parallel when it is available. There were several versions of gtkmm-2.4, such as gtkmm 2.10 and there will be 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. Theoretically, there might be a future gtkmm-4.0 API which would install in parallel with gtkmm-3.0 without affecting existing applications.

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

Openismus 有更多 帮助使用 automake 和 autoconf 的基础知识