Posted by: Airtower | 2010-06-14

Autotools and pthreads

Today, I’ve been setting up autotools for a little project of mine because it started using too many cflags to type in all the time. I used autotools before but still had to look up a lot of things, this document was quite helpful. If you’re searching for a beginner friendly tutorial, look here.

However, my earlier autotools-using projects did not use pthreads, and autoscan apparently does not handle this case automatically. Well, how do I get autotools to set the right flags?

Searching the net for a while, I found that ACX_PTHREAD from the AC Autoconf Macro Archive should do the trick. Gentoo has an ebuild for this macro library (sys-devel/ac-archive), so installing it was no problem. I just needed to figure out how to let autotools find the macro from the library. Solution:

  1. Add the macro to configure.ac
  2. Use the acinclude tool

I added the following to configure.ac:

ACX_PTHREAD
LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC"

Afterwards, running

$ acinclude

created a file called acinclude.m4. This file will be used automatically by the normal autotools run, and that’s it. 🙂

Update 2013-07-10: On Ubuntu, the packet containing the ACX_PTHREAD macro is called autoconf-archive, running acinclude is not necessary. A normal autoreconf will do.

Advertisements

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: