Beruflich Dokumente
Kultur Dokumente
6/25/12
EXAMPLES FROM gcnr: An example of using the above options is the little file named "gcnr", which we use to compile programs that use Numerical Recipes in C functions. The file "gcnr" is a one-line Unix script that issues the following command: gcc -Wall -ansi -pedantic -I/mit/recipes/src/recipes_c-ansi/include -L/mit/recipes/`machtype`lib $* -lrecipes_c-ansi -lm |& grep -v nrutil (Note that the above is a long command and may word wrap in your browser.) The numbers in this list mark each part of the command: 1. 2. 3. 4. 5. 6. 7. where 1. Tells Unix where to find the gcc program (`machtype` is needed to make sure that the correct version of gcc is used for the machine type you are using). 2. Tells gcc that it should look in the Num. Rec. in C include directory to find nr.h and nrutil.h when it encounters #include "nr.h" and #include "nrutil.h" in your code. 3. Tells gcc to look in the Num. Rec. in C library directory to find the pre-compiled binaries for all Num. Rec. in C functions used in your code. 4. Is the Unix script notation for the command line argument to the script. In other words, when you type "gcnr myfile.c", "myfile.c" will be substituted in place of "$*". 5. Specifies the name of the library of pre-compiled binaries for all Num. Rec. in C functions. It resides in the directory mentioned under (4). This option tells the linker to link in the Num. Rec. in C functions when building your program. 6. Tells the linker to link in the math library. The name of the math library (i.e., file of pre-compiled binaries for all math functions) is "libm.a". (See explanation of "-l" above.) 7. Pushes the output through a parsing program called grep. This looks through the output for lines containing "nrutil" and ignores them. This removes a number of error messages that do not prevent the executable from functioning. CONCLUSION: There are MANY options to gcc which can be used to make programming easier and faster. These are only a few of the more common ones. As mentioned above, the man pages for gcc list them all.
last modified: 01/08/2001 19:50:52
web.mit.edu/10.001/Web/Tips/tips_on_gcc.html
2/2