Week 7 Notes for DAT2330 - Ian Allen Supplement to Text, outlining the material done in class and lab. Remember - knowing how to find out the answer is more important than memorizing the answer. Learn to fish! RTFM![*] ([*] Read The Fine Manual) ------------------- Miscellaneous Notes ------------------- Unscrambling a terminal that is in graphics characters set mode: - if what you are typing appears as line drawing characters instead of letters - this might happen after you accidentally use "cat" to send a non-text file to your terminal screen, e.g. cat /bin/ls - To Fix: - On Floppix type: setterm -reset - On ACADAIX type: reset - On either type: echo ^V^O (that's CTRL-V CTRL-O) GNU - Gnu's Not Unix - Free Software Foundation (FSF) project - rewrite Unix in the public domain (the way it started out) - chief architect: Richard Stallman (original author of EMACS) Linux distribution == Linux Kernel + GNU Utilities - The GNU kernel hasn't progressed far (named HURD) - So, we use the Linux kernel with all the GNU utility software ---------------------------- Building C Language Programs ---------------------------- Text - Chapter 14 - p.541-545 Understanding Unix "compile, link, and stop". gcc vs cc - vendors started selling the C compiler "cc" separately to make money - many shops now use the free (CopyLeft) GNU C Compiler: gcc - Floppix is too small to have either compiler - ACADAIX only has "cc" - NETSRV (Solaris) only has "gcc" - Regular Linux distributions come with "gcc" "cc" and "gcc" are "front-ends" to the compiler and linker - if you supply source files (*.c), the compiler will be used - if you supply object files (*.o), the linker will be used - if you supply both, both will be used What does the linker name the output of the link step? - a.out When do you type "a.out" and when do you type "./a.out"? - when you have or don't have the current directory in your PATH - don't put the current directory in your PATH; it's a security risk Understand: Figure 14-2: Read the first part of "Compiling and Linking a C Program" - Preprocessor Input: Text files: Your source code Output: Text files: Source code with macros and header files expanded and included - Compiler Input: Text files: Source code with macros and header files expanded and included Output: Text files: Assembly-language symbolic source code for your processor - Assembler Input: Text files: Assembly-language symbolic source code for your processor Output: Object files: Binary, machine-readable instructions for your processor - Linker Input: Object files (including ones taken from system libraries) Output: one Binary: An executable, machine-language program containing everything needed to execute. Understand: Figure 14-3: Dependency Graph for building a program from source. foo -> foo.o -> foo.c Which parts of the process produce which kinds of error messages? - preprocessor - if you mis-spell a file name on the command line - if you mis-spell an #include name - if you use an unknown #-directive - compiler - if you leave off a semicolon or mis-match parentheses - if you have undeclared variables - most other syntax errors - linker - if you use an unknown library function (mis-spelling?) - if you declare two external objects with the same name - e.g. two global functions with the same name cc and gcc - The -c option tells the compiler to stop once the *.o is built - don't call the linker - the name of the *.o is taken from the *.c source file - The -o option is used to change the default name of the output file - to have the linker change "a.out" to something reasonable make - "make" is a Unix program that reads a text Makefile and builds things - things are usually programs, but could be anything - the first thing in the Makefile is the thing being made - usually this is the name of the binary we are building - Makefile is built from dependencies and commands - dependencies are read by the make command, not by the SHELL - each command line starts with a TAB character - each command line is passed to the SHELL for execution Sample Makefile: # This is a sample Makefile to build foo from source. # idallen@ncf.ca foo: foo.o ___TAB___ cc -o foo foo.o foo.o: foo.c ___TAB___ cc -c foo.c Another Sample Makefile: # This is a sample Makefile to build dog from source. # idallen@ncf.ca dog: cat.o ___TAB___ cc -o dog cat.o cat.o: cat.c ___TAB___ cc -c cat.c (See the text for another example.)