Summary of Compilation Tools


 
cc/gcc - compiles and links C code/object files

-c		build object file
-o <file>	output file name
-l<x>		use lib<x> (-lm forr math library)
-L<dir>		search for libraries inn <dir>
-I<dir>		search for header(*.h)  files in <dir>
-g		debugging info
-D<X>		define <X>
-U<X>		undefine <X>
-E		only preprocess
-v		verbose (show commands executed)

Usage:
$ cc -c a.c				# compile a.o
$ cc -o prog prog.c			# compile & link prog.c
$ cc -I../include a.c			# search for *.h in ../include
$ cc -o a1 a1.o -L/home/g/lib -ldbg 	# use libdbg and search for libraries in /home/g/lib


ld - links object files

-o <file>	output file name
-l<x>		use lib<x>
-L<dir>		search for libraries inn <dir>

Usage:
$ ld  /usr/lib/crt0.o prog.o -lc -o prog	# link prog.o to prog


ar - builds archives/libraries

-c		create archive
-d		remove file from archive
-r		replace/add file to archive
-t		list archive
-x		extract file from archive

Usage:
$ ar -cr libab.a a.o b.o	# create libab.a from a.o, b.o
$ ar -t libab.a			# show files in libab.a
$ ar -d libab.a a.o		# remove a.o
$ ar -r libab.a a.o		# replace a.o


nm - print name list of archive, object file or executable

Usage:

$ nm a.o			# show symbols in a.o
$ for lib in /usr/lib/*.a; do 
	echo $lib; nm $lib | grep aoi_write
done 				# find which library contains aio_write


cpp - C preprocessor, preprocesses C code

-I<dir>		search for header(*.h) files in <dir>
-D<X>		define <X>
-U<X>		undefine <X>


make/gmake - rules based tool for building programs, libraries

	-v/--version	version information (gmake)
	-p			show suffix rules
	-n			show commands but don't execute
	-f file		use file instead of [Mm]akefile

Usage:
$ make all			# build everything
$ make install			# install headers, libraries, executables
$ make clean			# remove .o files
$ make purge			# remove/uninstall everything
$ make CC=/opt/ansic/bin/cc all # use /opt/ansic/bin/cc for CC
$ make -n all > output		# show build commands

Common make variables

CC		C compiler
AR		archive program
CPP		C preprocessor
LD		linker
CPPFLAGS	contains -I -D -U options
CFLAGS		contains C compiler options 
LIBS		contains -l options
LDFLAGS		contains -L options
SRCS		source files
OBJS		.o files
Hosted by www.Geocities.ws

1