g++

Assume that hello.C contains the following program.

#include	

int
main(int argc,char *argv[])
{
cout << "hello world" << endl;
}
The following line compiles hello.C into an executable file a.out.
tinf2% g++ hello.C      # compile & link; exec file is a.out
tinf2% a.out		# execute
hello world
tinf2% g++ -o hi hello.C        # compile & link; exec file is after -o
tinf2% hi
hello world
tinf2%
The most important options are illustrated below:
tinf2% g++ -c hello.C   # compile, don't  link; object file is hello.o
tinf2% g++ -o ciao hello.o other.o # just link, exec file is after -o
tinf2% g++ -o ciao hello.o -L/usr/local/tbc++/lib -ltbcc
	# link also with /usr/local/tbc++/libtbcc.so
tinf2% g++ -o ciao hello.o -R/usr/local/lib/tbcc:/usr/local/mylibs \
	-L/usr/local/tbc++/lib -ltbcc
	# also store library path after -R in executable ciao
tinf2% g++ -I/usr/local/tbc++/include -c hello.C # find include files in ..
tinf2% g++ -c -Wall hello.C # generate warnings for suspicious constructs
tinf2% g++ -c -O2 hello.C # optimize
tinf2% g++ -c -g hello.C # generate debug info for ddd
tinf2% g++ -c -fPIC hello.C
	# generate position-independent code for shared library (dll in windoze)
tinf2% g++ -shared -o libhello.so hello.o # make shared library
  • g++ iostream
  • g++ faq
  • gnu.g++.help newsgroup
    Dirk Vermeir (dvermeir@vub.ac.be) [Last modified: Mon Oct 5 13:39:05 MET DST 1998 ]