Autoconf from zero to libreadline

Hi all. Let’s say we want to use Autoconf, and that we already know how to program something in C/C++… Here is how I do it, in what probably will become a series. I also want to write an article on how to use autoconf to generate real win64 executables, and how to make an installer for those executables, all from the comfort of your Linux terminal. Stay tuned..


  1. How to start using Autoconf in a C++ program.
  2. Write and
  3. Generate ./configure
  4. Make the tarball.
  5. Including a dependency: libreadline.

Let’s make the simplest possible C++ program like this:

#include <iostream>
int main(int argc, char* argv[]) {
  std::cout << "Hello, world!\n";
  return 0;

We stuff it in a file called ‘’ and compile it like this:

g++ -o hello

How to start using Autoconf in a C++ program

Autoconf is a bunch of packages, which are all named slightly differently under the different distributions.

dnf -y install autoconf automake libtool # fedora
apt-get -y install autoconf automake libtool # debian

We use basically use one autoconf command thoughout: autoreconf.

Write and

Let’s make the simplest possible Autoconf configuration: one file ‘‘ for the configuration of autoconf for this project, and ‘‘ to generate our ‘Makefile‘.

AC_INIT([hello], [1.0.0], [], [], [])


And the

bin_PROGRAMS = hello
hello_SOURCES =

That’s it when it comes to files we need to create and understand. Now would be a great time to create your git repository: git init ; git add * ; git commit -am initial

We create the autoconf cruft files by issuing:

autoreconf -if

Where -if tells autoreconf to regenerate all Makefile and cruft files from scratch. To make the Makefile, and build the project, issue:

./configure --prefix=$HOME/usr # this is where my progs live
make dist # create the hello-1.0.0.tar.gz tarball distfile

Including a dependency: libreadline

You could clone libreadline from it’s GNU repository, but everybody uses the easy way with the package manager:

dnf -y install readline-devel # fedora
apt-get -y install libreadline-dev # debian

at this point, you should be able to do:

g++ -o hello -lreadline

Now to add this to Autoconf, we need to add lreadline to the, like this:

bin_PROGRAMS = hello
hello_SOURCES =
dockerdeps_LDADD = -lreadline

And a C/C++ program using libreadline could be something like this:

#include <iostream>

#include <stdio.h>
#include <readline/readline.h>

int main(int argc, char* argv[]) {
  auto name = readline("Enter your name: ");
  std::cout << "Hello, \"" << name << "\".\n";
  return 0;

Leave a Comment

Your email address will not be published. Required fields are marked *