Do you want to take your existing autotools project and to add support for the Boost libraries? I want to specifically use Boost Threading, so I have included everything that I did to make my project as well as the full source code included at the bottom of this article.
If you want to read a nice guide on how to use threading in Boost visit this link:
Step 1 – Download Boost M4 Macros
Modify your configure.ac file to use some Boost macros. In order for autotools to find these macros you will have to download them from the GNU autoconf archive. For Boost Threading support you will need to download:
Place those files into the m4 sub-directory of your project.
Step 2 – Reference M4 Macros Directory
Your configure.ac should now reference the m4 macros directory by adding the AC_CONFIG_MACRO_DIR macro call like so:
Your Makefile.am file should also have a call to another macro to enable these changes as well:
ACLOCAL_AMFLAGS = -I m4
Step 3 – Call the Boost Macros from your configure.ac file
Now we have to make another change to your configure.ac file, we need to call the actual Boost Macros provided by the m4 files which you added to your project before. Make sure you add these calls after the call to the AC_CONFIG_MACRO_DIR (obviously):
AX_BOOST_BASE([1.53],,[AC_MSG_ERROR([projectX needs Boost, but it was not found in your system])]) AX_BOOST_SYSTEM AX_BOOST_THREAD
Step 4 – Modify your Makefile.am file to add the bootstrap directory
Add a reference to a variable named EXTRA_DIST so that your project will find the necessary Boost files when building.
EXTRA_DIST = bootstrap
Step 5 – Modify your src/Makefile.am to add some link parameters to allow your linker to properly find the Boost libraries.
Modify your src/Makefile.am file to include some parameters to cause it to link to the proper boost libraries as well:
AM_CPPFLAGS = $(BOOST_CPPFLAGS) AM_LDFLAGS = $(BOOST_LDFLAGS) <app_name>_LDADD = \ $(BOOST_THREAD_LIB)
Step 6 – Recreate your config files by running the same steps as you normally do and rebuild your code, now with Boost Threading support!
autoreconf -fvi ./configure make
You can download the associated source code here:
Note to cygwin users:
If you want to download the boost libraries, you will have to use a mirror that has the boost-devel package. You can use the truefunny.com mirror here: http://truefunny.com/cygwin while running the cygwin installer. If you are using apt-cyg, run the following command:
apt-cyg -m http://truefunny.com/cygwin install boost-devel
Do you want to take your existing autotools project and to add support for the Boost libraries? I want to specifically...