Creating a Skeleton C++ Project using GNU autotools

Installing the Software

Ensure you have a working system with autoconf automake make g++ gcc etc... Debian packages can be installed with the following command:

# apt-get install build-essential automake autoconf

or if your using aptitude...

# aptitude install build-essential automake autoconf

Creating the Script

Run the script below to create your new project in your current directory. To do this you will need to copy and paste the script into a file using your preferred text editor and then make the script executable:

$ chmod +x createproject

...substitute createproject with the filename of the script you just created.

Running the Script

Now run the script:

$ ./createproject

Once the script is complete you can start editing your C++ source (Main.cpp) and simply issue the command

$ make

Other Methods

For a more complete but slightly more complex solution you can use GNU autoproject.

Most Integrated Development Environments (IDEs) will do all this for you such as KDevelop.

The Script

cut and paste from the next line down --->

 1. Create a new C++ Automake Project Folder
 1. Create project directory and misc. files ...
echo "Please enter a project name (no spaces) ..."
read projectname
mkdir -p "$projectname"
cd "$projectname"
mkdir src
touch NEWS README AUTHORS [[ChangeLog]]

 1. Create skeleton C++ code
echo '#include <string>' > src/Main.cpp
echo '#include <iostream>' >> src/Main.cpp
echo '' >> src/Main.cpp
echo 'int main(int argc, char *argv[]){' >> src/Main.cpp
echo '  std::cout << "Project skeleton code succesfully compiled and executed." << std::endl;' >> src/Main.cpp
echo '  return 0;' >> src/Main.cpp
echo '}' >> src/Main.cpp

 1. Create ...
echo 'AC_INIT(src/Main.cpp)' >
echo 'AM_INIT_AUTOMAKE('$projectname',0.1)' >>
echo '#AM_CONFIG_HEADER(config.h)' >>
echo 'AC_PROG_CC' >>
echo 'AC_PROG_CXX' >>
echo '#AC_PROG_LIBTOOL' >>
echo 'AC_OUTPUT(Makefile src/Makefile)' >>

 1. Create ...
echo 'SUBDIRS = src' >
echo 'EXTRA_DIST =' >>

 1. Create src/ ...
echo 'bin_PROGRAMS = '$projectname > src/
echo 'CXXFLAGS = -O2' >> src/
echo $projectname'_SOURCES = Main.cpp' >> src/
echo 'LDADD = ' >> src/
echo 'noinst_HEADERS = ' >> src/

 1. Run aclocal ...

 1. Run autoconf...

 1. Run automake ...
automake --add-missing

 1. Run configure...

 1. Compile program

 1. Execute program

 1. Finished
echo "Project creation complete."

July 2004 SimonCapstick

LinuxHints/SimpleCPlusPlusProject (last edited 2006-03-22 19:02:41 by 212)