C and C++ on NYU’s Solaris Unix

Log into Unix

To use the Sun Solaris Unix host i5.nyu.edu, get your loginame (same as your NYU NetID) and secret password (same as your NYU NetID secret password) if you do not already have them. Then connect to i5.nyu.edu via the Secure Shell protocol SSH.

Unix editors

To edit a file on i5.nyu.edu, use one of the Unix editors:

Compilers

i5.nyu.edu has three pairs of C and C++ compilers. The ones in teh first column are broken; use the ones in the second column. To get the C++0x extensions, give the command line argument -std=c++0x to /opt/gcc453/bin/g++.

  GNU version 4.5.3 GNU version 4.5.2 GNU version 3.4.6
C /opt/gcc453/bin/gcc /usr/bin/gcc /usr/local/bin/gcc
C++ /opt/gcc453/bin/g++ /usr/bin/g++ /usr/local/bin/g++

On Linux, install the packages for gcc and gcc-c++ if you don’t already have them.

Compile and run the first program we did in class

cd
pwd
cp ~mm64/public_html/INFO1-CE9264/src/hello.C hello.C
ls -l hello.C
/opt/gcc453/bin/g++ hello.C
ls -l a.out
./a.out
Hello, world!
This is an error message.
echo $?
0
./a.out > output.txt 2> errors.txt
ls -l output.txt errors.txt
./a.out > both.txt 2>&1
ls -l output.txt errors.txt

The program that comprises more than one source file in §1.7.2

cd
pwd
cp ~mm64/public_html/book/src/sources/fg.h fg.h
cp ~mm64/public_html/book/src/sources/fg.C fg.C
cp ~mm64/public_html/book/src/sources/main.C main.C
ls -l fg.h fg.C main.C
/opt/gcc453/bin/g++ main.C fg.C
ls -l a.out
./a.out

The terminal test program in Homework 1.7.3a

The -I. option ensures that the compiler will include ~mm64/book/src/term/term.h, not some other term.h file. The -D option defines the macro UNIX, which is used in the term.c file.

cd
pwd
cp ~mm64/public_html/book/src/term/term.h term.h
cp ~mm64/public_html/book/src/term/term.c term.c
cp ~mm64/public_html/book/src/term/main.C main.C
ls -l term.h term.c main.C
/opt/gcc453/bin/gcc -I. -DUNIX= -c term.c
ls -l term.o
/opt/gcc453/bin/g++ -I. main.C term.o -lcurses
ls a.out
./a.out