Last
month's newsletter described how to use the new GNU
autotools support in ACE to automatically configure ACE on
most non-Windows platforms. The new scheme makes it much
easier to configure ACE for a new platform, and will be much
more familiar to people used to using the autotools to build
other open source software packages.
But once ACE is configured and built, you're still left
with figuring out how to build your ACE-using application.
When using ACE's traditional configure/build method, you need
to either structure your application's makefiles to use ACE's
GNU make structure, or extract the pertinent compile and link
options from ACE's files and insert them into your
application's makefiles. This step is a common source of
confusion and build errors because there are a number of
settings and compile switches for your application that must
match ACE's build options in order to successfully compile and
link an ACE-using program.
The good news is that ACE's autotools support also assists
your efforts to cleanly integrate with your local ACE build.
The pkg-config facility is the means by which you can be sure
to use the correct compile and link options for your
application. This is how it works:
- When you use ACE's
configure script to
configure ACE, the pertinent compile and link options are
saved.
- The
pkg-config command accesses the options
saved by ACE's configure script, making them available to
you.
Generally, the pkg-config command will try to
access configure information for an installed package (the
Makefiles generated using ACE's autoconfigure support also
allow you to install the resulting ACE build) but you can also
specify the directory to your uninstalled ACE build using the
PKG_CONFIG_PATH environment variable. For example, if you
unpacked the ACE sources into
/home/shuston/ACE_wrappers and configured ACE in
the build subdirectory, you would set (or append
to) PKG_CONFIG_PATH
/home/shuston/ACE_wrappers/build/ace.
The pkg-config command has a number of options
to specify which information you'd like to retrieve. For
example, if you have a single-file application with source
file myapp.cpp, you could build it with the
following command:
g++ -o myapp myapp.cpp `pkg-config --cflags --libs ACE`
The --cflags option retrieves the
preprocessor/compile flags needed for compilation and the
--libs option retrieves the needed link options
to include ACE as well as any libraries that ACE depends on.
And, the same pkg-config command can be
used for any of the libraries supplied with ACE, such as
ACE_SSL and ACEXML. Just remember to include the proper
directories in PKG_CONFIG_PATH if your ACE build
is not installed.
Very cool, huh? Riverace support customers can always ask
further questions about this facility, and get more advice
about how to best apply this feature.