50 likes | 199 Views
Unix tools for C/C++ Programming. CS240 Computer Science II. Entering a program. You may use either vi or pico editor that is available on our system to enter your source code. The C and C++ source code must saved with a .c or .cpp extension, respectively.
E N D
Unix tools for C/C++ Programming CS240 Computer Science II
Entering a program You may use either vi or pico editor that is available on our system to enter your source code. The C and C++ source code must saved with a .c or .cpp extension, respectively.
Compiling the source code • The cc utility calls the C preprocessor, C compiler, the assembler, and the link editor. If there is no error, an executable load module a.out is generated for the C program. • The g++ utility performs the same tasks for a C++ program.
cc and g++ options • -l: requests the compiler to search the other libraries. Note that the option appears after the filenames. In the example below, the compiler will search the math library libm.a (by default, the compiler searches the the standard library libc.a). $ ccprog.c -lm # m stands for libm.a • -O: causes the compiler to use the optimizer and lists all the object files with .o extension. • -o: allows the user to replace default a.out with a different name. $ g++ -o Hello Hello.cpp # Hello replace a.out $ Hello # executes the code • -c: supresses the link-edit phase; it does not treat unresolved external references as errors. Once all modules have separately debugged, one can recompile by listing as arguments in the cc or g++ command the needed .c, .cpp, or .o files.