how to compile a file? say you have test.cc and test.hh now, to compile and link it:
> g++ -c test.cc
> g++ -o test test.o
then you can run the exutable "test" you got. GCC docs

g++ options:

  1. -o output file
  2. -c compile but not link
  3. -L, -I include and lib paths
  4. -l link a lib
  5. -g insert debugging info in your exutable
  6. -Wall turn on warnings
  7. -fPIC position independent code (dosen't work sometimes)
  8. -O optimize


the easiest one:
# this is a example of Makefile

test: test.o
        g++ -o test test.o
test.o: test.cc test.hh
        g++ -c test.cc
        rm test test.o
Something maybe useful is to tell gcc how to compile all, say .cc files:
        g++ -c $< $(INCLUDES)
The variable "$<" refers to dependency. And "$@" is target

I stole this longer example from http://www.pma.caltech.edu/~physlab/ph21_winter06/make.html, to show you other than compiling, Makefile can also do automatic work for you:

# Makefile

CPP = g++
CPPFLAGS = -g -Wall

# If output data is up to date, plot it.
plot: output-data
       xmgrace output-data

# If output data is not up to date, recreate it by running the program.
output-data : program input-data

# Compile the program.
program : program.cpp
       $(CPP) $(CPPFLAGS) -o program program.cpp $(LDFLAGS)

# command to be executed.
       rm -f program output-data

GNU Auto-tools

I would recommend this documentation: GNU Autobook Below are some shallow examples I have tested

GNU Autoconf and Automake and etc

most of this part comes from http://www.seul.org/docs/autotut/

When your project grows large, it is almost impossible to write all the Makefile by hand. Therefore we need some automatic tool to do the job with minimum input. The production line for automake and autoconf is shown by this

Basically, autoconf will use configure.in to generate the configure script; automake will use Makefile.am to generate Makefile.in. Then configure will check your environment and use Makefile.in to generate Makefile.

A example for autoconf and automake

In general, all you need to write is a configure.in in the top dir of your package, and Makefile.am in all the dirs within the package. Otherwise, you can run the perl script "autoscan" to get a primitive version of configure.in and you may also want to edit that to best fit your actual needs.

Here is the example of a simple project, there is only once source code, and the structure looks like this:

|-- ChangeLog
|-- Makefile.am
|-- NEWS
|-- configure.in
`-- src
    |-- Makefile.am
    |-- test.cc
    `-- test.hh
The configure.in is shown below. The important lines are ACINIT, AM_INIT_AUTOMAKE, AC_CONFIG_FILES, and AC_OUTPUT:
# Process this file with autoconf to produce a configure script.
AM_INIT_AUTOMAKE(test, 0.0.1)

# Checks for programs.

AC_CONFIG_FILES([Makefile src/Makefile])
The Makefile.am looks like:
# used by automake
then src/Makefile.am looks like:
# used by automake
bin_PROGRAMS = test
test_SOURCES = test.cc
noinst_HEADERS = test.hh
To generate configure script and Makefile.in, you need to run the following commands which belongs to the "auto" family:
autoconf --add-missing --copy
After this, you all know how to install it:
./configure --prefix=<somewhere>
make install
There are some standard features for the Makefile you got by automake, the useful ones are make clean, make dist (generate the tar-ball for your distribution), make distclean and etc.

Aclocal and m4 scripts

if you want to have more complicated features in configure script, you can try aclocal. This tool will generate the file aclocal.m4, this m4 script will be seen by autoconf. For example, you want to test a special package or echo some information in configure, you can do that in a m4 script acinclude.m4, this will be automatically included by aclocal; or you can put them in a dir, then include them by this:
aclocal -I <dir>
aclocal will search .m4 scripts in that dir.


to be continued ...

Compiling using MinGW under Windows Vista

1. MinGW must be located on the same partition as the files you want to compile 2. env variable %GCC_EXEC_PREFIX% needs to be set to MinGW path




Standard directories in automake


libtool and .la files


dump gcc predefined macros

gcc -dM -E - < /dev/null