g++
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.othen you can run the exutable "test" you got. GCC docs
g++ options:
- -o output file
- -c compile but not link
- -L, -I include and lib paths
- -l link a lib
- -g insert debugging info in your exutable
- -Wall turn on warnings
- -fPIC position independent code (dosen't work sometimes)
- -O optimize
Makefile
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
clean:
rm test test.o
Something maybe useful is to tell gcc how to compile all, say .cc files:
%.o:%.cpp
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
LDFLAGS = -lm
# 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
./program
# Compile the program.
program : program.cpp
$(CPP) $(CPPFLAGS) -o program program.cpp $(LDFLAGS)
# command to be executed.
clean:
rm -f program output-data
GNU Auto-tools
I would recommend this documentation: GNU Autobook Below are some shallow examples I have testedGNU 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:
.
|-- AUTHORS
|-- COPYING
|-- ChangeLog
|-- INSTALL
|-- Makefile.am
|-- NEWS
|-- README
|-- 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. AC_INIT(src/test.cc) AM_INIT_AUTOMAKE(test, 0.0.1) AM_CONFIG_HEADER(config.h) # Checks for programs. AC_PROG_AWK AC_PROG_CXX AC_PROG_CC AC_PROG_INSTALL AC_PROG_LN_S AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUTThe Makefile.am looks like:
# used by automake SUBDIRS = srcthen src/Makefile.am looks like:
# used by automake bin_PROGRAMS = test test_SOURCES = test.cc noinst_HEADERS = test.hhTo generate configure script and Makefile.in, you need to run the following commands which belongs to the "auto" family:
aclocal autoheader autoconf --add-missing --copy automakeAfter this, you all know how to install it:
./configure --prefix=<somewhere> make make installThere 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.
libtoolize
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
references:
http://wiki.codeblocks.org/index.php?title=Installing_MinGW_with_Vista
Standard directories in automake
http://www.gnu.org/software/hello/manual/automake/Standard-Directory-Variables.html
libtool and .la files
http://blog.flameeyes.eu/2009/09/28/removing-la-files-for-dum-w-uncertain-people
dump gcc predefined macros
gcc -dM -E - < /dev/null
