ThreadMentor: Compile and Run Your Programs

Since the CS Department does not use Windows machines for your programming assignments, we only discuss the way of compiling and running your programs on Sun Solaris and Linux. ThreadMentor uses Sun Solaris thread on Sun systems, and Linux threads and Pthread on Linux. However, I strongly encourage you to use the former as a good reference because it is a more robust implementation.

Sun Solaris

Suppose you have a program with three files quicksort.h (thread definition), quicksort.cpp (thread implementation) and quicksort-main.cpp (the main program). The following makefile compiles this program to an executable file quicksort with the visualization system included:
CC        = c++
CFLAGS      = -g -O2
DFLAGS    = -DPACKAGE=\"threadsystem\" -DVERSION=\"1.0\" -DPTHREAD=1 -DUNIX_MSG_Q=1 -DSTDC_HEADERS=1
IFLAGS    = -I/usr/local.csl/ThreadMentor/solaris/include
TMLIB     = /usr/local.csl/ThreadMentor/solaris/Visual/libthreadclass.a

OBJ_FILE  = quicksort.o quicksort-main.o
EXE_FILE  = quicksort

${EXE_FILE}: ${OBJ_FILE}
     ${CC} ${FLAGS}  -o ${EXE_FILE}  ${OBJ_FILE} ${TMLIB} -lpthread -lrt

quicksort.o : quicksort.cpp quicksort.h
     ${CC} ${DFLAGS} ${IFLAGS} ${CFLAGS} -c quicksort.cpp

quicksort-main.o: quicksort-main.cpp quicksort.h
     ${CC} ${DFLAGS} ${IFLAGS} ${CFLAGS} -c quicksort-main.cpp

clean:
     rm -f ${OBJ_FILE} ${EXE_FILE}
Click here to download a copy of this file, and here to learn more about makefiles.

If you do not want the visualization system, you can replace Visual with NoVisual. The following is an example:

CC        = c++
CFLAGS      = -g -O2
DFLAGS    = -DPACKAGE=\"threadsystem\" -DVERSION=\"1.0\" -DPTHREAD=1 -DUNIX_MSG_Q=1 -DSTDC_HEADERS=1
IFLAGS    = -I/usr/local.csl/ThreadMentor/solaris/include
TMLIB     = /usr/local.csl/ThreadMentor/solaris/NoVisual/libthreadclass.a

OBJ_FILE  = quicksort.o quicksort-main.o
EXE_FILE  = quicksort

${EXE_FILE}: ${OBJ_FILE}
     ${CC} ${FLAGS}  -o ${EXE_FILE}  ${OBJ_FILE} ${TMLIB} -lpthread -lrt

quicksort.o : quicksort.cpp quicksort.h
     ${CC} ${DFLAGS} ${IFLAGS} ${CFLAGS} -c quicksort.cpp

quicksort-main.o: quicksort-main.cpp quicksort.h
     ${CC} ${DFLAGS} ${IFLAGS} ${CFLAGS} -c quicksort-main.cpp

clean:
     rm -f ${OBJ_FILE} ${EXE_FILE}
Click here to download a copy of this file, and here to learn more about makefiles.

To run your program successfully, two lines must be added to your .cshrc file, which is in your home directory:

setenv LD_LIBRARY_PATH  /usr/local.csl/ThreadMentor/solaris/lib:$LD_LIBRARY_PATH 
set path=($path /usr/local.csl/ThreadMentor/solaris/bin) 
These two lines permit the system to find the visualization system when you need it.

Linux

Suppose you have a program with three files quicksort.h (thread definition), quicksort.cpp (thread implementation) and quicksort-main.cpp (the main program). The following makefile compiles this program to an executable file quicksort with the visualization system included:
CC       = c++
CFLAGS   = -g -O2
DFLAGS   = -DPACKAGE=\"threadsystem\" -DVERSION=\"1.0\" -DPTHREAD=1 -DUNIX_MSG_Q=1 -DSTDC_HEADERS=1
IFLAGS   = -I/usr/local.csl/ThreadMentor/fedora4/include
TMLIB    = /usr/local.csl/ThreadMentor/fedora4/Visual/libthreadclass.a

OBJ_FILE = quicksort.o quicksort-main.o
EXE_FILE = quicksort

${EXE_FILE}: ${OBJ_FILE}
        ${CC} ${FLAGS}  -o ${EXE_FILE}  ${OBJ_FILE} ${TMLIB} -lpthread

quicksort.o : quicksort.cpp quicksort.h
        ${CC} ${DFLAGS} ${IFLAGS} ${CFLAGS} -c quicksort.cpp

quicksort-main.o: quicksort-main.cpp quicksort.h
        ${CC} ${DFLAGS} ${IFLAGS} ${CFLAGS} -c quicksort-main.cpp

clean:
        rm -f ${OBJ_FILE} ${EXE_FILE}
Click here to download a copy of this file, and here to learn more about makefiles.

If you do not want the visualization system, you can replace Visual with NoVisual. The following is an example:

CC       = c++
CFLAGS   = -g -O2
DFLAGS   = -DPACKAGE=\"threadsystem\" -DVERSION=\"1.0\" -DPTHREAD=1 -DUNIX_MSG_Q=1 -DSTDC_HEADERS=1
IFLAGS   = -I/usr/local.csl/ThreadMentor/fedora4/include
TMLIB    = /usr/local.csl/ThreadMentor/fedora4/NoVisual/libthreadclass.a

OBJ_FILE = quicksort.o quicksort-main.o
EXE_FILE = quicksort

${EXE_FILE}: ${OBJ_FILE}
        ${CC} ${FLAGS}  -o ${EXE_FILE}  ${OBJ_FILE} ${TMLIB} -lpthread

quicksort.o : quicksort.cpp quicksort.h
        ${CC} ${DFLAGS} ${IFLAGS} ${CFLAGS} -c quicksort.cpp

quicksort-main.o: quicksort-main.cpp quicksort.h
        ${CC} ${DFLAGS} ${IFLAGS} ${CFLAGS} -c quicksort-main.cpp

clean:
        rm -f ${OBJ_FILE} ${EXE_FILE}
Click here to download a copy of this file, and here to learn more about makefiles.

To run your program successfully, one line must be added to your .cshrc file, which is in your home directory. You should modify the following if you use a different shell language.

set path=($path /usr/local.csl/ThreadMentor/fedora4/bin)
These two lines permit the system to find the visualization system when you need it.