Unix C++ QuickStart
This should help you to start programming in C++ using the Unix compilers available here at the University of Michigan.
- Log on to your Unix account.
- Create your source code file using a text editor such as vi or emacs.
Give it the extension "cpp" - other extensions will work, but this is the
"standard" one for this course and will be assumed in grading.
- Ensure that your file has been saved to the disk.
- Compile your file with a command line like the following, where "p1.cpp"
represents the source file for your project, and "p1" is the name of the executable
file for your project (it can be different from the source file name):
g++ -o p1 p1.cpp -lm
g++ is one of the names for the GNU C++ compiler. "p1.cpp" names the file
containing the source code. The "-o" option means that the following file
name should be used as the name of the executable file ("a.out" is assumed
if you leave the "-o " option out). The "-lm" option tells the
linker to link in the math library.
- If there is a problem, error messages will appear on your display. Each
message will name a file and a line number in the file locating the
problem. Use your text editor to fix the source code - use the line numbers
if it isn't obvious where the problem is. Save the file and issue the compile command again.
- If the program has compiled and linked successfully, start execution by
typing the name of the executable file:
p1
The program will start running and the output will appear on your display.
To interrupt the program, type control-C, and you will get a Unix command
line prompt again.
To use a debugger, you must tell the compiler to save the symbol table
information. Do this with the "-g" option in the compile command, as in:
g++ -o p1 -g p1.cpp -lm
We will be providing a debugger QuickStart soon.
To avoid having to retype the compile command every time, use the "make" utility. This is helpful even for simple projects, but is essential for complex projects later in the course, so we recommend that you get started using it now.
Makefile Quickstart