-------------------------------- DAT2330 - Unix - Prof. Ian Allen -------------------------------- Chapter 14 - Programming Tools (excerpts) We will concentrate on the basic Compile, Link, and Go sequence. Sections covered: Intro p.537-541 Compiling and Linking p.541-543 Compiler Warnings p.551 Notes: - Usually when you are asked to "compile" a program, the intent is to compile it and link it into a runnable module. - The indentation used in the tabs.c program on p.539 is not standard. (The author did not indent inside functions.) Since GNU/Linux is an open-source operating system, you can see "standard" C indentation style by reading the source code available. You can find the Linux kernel source code under /usr/src/linux/ on the Linux Test Machine. A sample file would be: /usr/src/linux/kernel/time.c NOTE: The IBM ACADAIX native compiler is named "cc", not "gcc", and it has a very different set of options. The basic use of "-c", "-l", "-o" and a few others are the same as Linux (as they have been in use since 1975); but, the other options may be different. The ACADAIX "cc" compiler will accept both C language (*.c) and C++ lanugage (*.C) source files. Note the upper-case suffix! Chapter summary: - Use the "-Wall" option to gcc (or to "g++") to turn on warnings about possible coding errors. Use the "-g" option to generate symbol tables for symbolic debuggers such as "gdb". - If you don't use the "-o" option, the output load module, linked and ready to run, is left in the file "a.out" in the current directory. Compile and link a C program from several C source files: gcc -Wall -g one.c two.c three.c Compile several C source files into object code without linking: gcc -c -Wall -g one.c two.c three.c Link several object files (*.o) into one program without compiling: gcc -Wall -g one.o two.o three.o Compile and link a C++ program from several C++ source files: g++ -Wall -g -o myprog a.C b.C c.C (note the upper-case suffix!) Here is some source code for some test programs: This version is C language: /******************************************************************/ /* A program to print command line arguments -IAN! idallen@ncf.ca */ /******************************************************************/ #include int main(int argc, char **argv){ int i; for( i=0; i int main(int argc, char **argv){ int i; for( i=0; i