Davehudsn
asked on
PThread compile problem on Knoppix with g++
I have a simulation program that I am trying to get working under knoppix using g++
I see that PThread.h is in the /usr/include directory, but it looks to me from the error messages that it is not finding the appropriate processes.
Here are the associated files:
script that does the compile/link:
clear
clear
echo '------------------------- ---------- ---------- ---------- ---------- -------
-------'
echo '------ Psim3 C++ (POSIX threads) package for object oriented simulation
-------'
# echo '------------------ (C) J. M. Garrido, 2004 -----------'
echo '------------------------- ---------- ---------- ---------- ---------- -------
-------'
g++ -w -pthread $1 /usr/psim3/libpsim3.a -I/usr/psim3 -lm
# the following are for bash and pdksh
#if [ "$2" != "" ] # change to parethesis for tcsh
#then
# mv a.out $2
# echo "$2 created."
#else
echo "a.out created."
#fi # change to endif fot tcsh
echo ' '
Here are the error messages:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---
------ Psim3 C++ (POSIX threads) package for object oriented simulation -------
-------------------------- ---------- ---------- ---------- ---------- ---------- ---
/tmp/ccXpJn2d.o(.text+0x1d ): In function `CPU::CPU[not-in-charge](c har*)':
: undefined reference to `process::process[not-in-c harge](cha r*, objtype)'
/tmp/ccXpJn2d.o(.text+0x5d ): In function `CPU::CPU[not-in-charge](c har*)':
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0x93 ): In function `CPU::CPU[in-charge](char* )':
: undefined reference to `process::process[not-in-c harge](cha r*, objtype)'
/tmp/ccXpJn2d.o(.text+0xd3 ): In function `CPU::CPU[in-charge](char* )':
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0xf4 ): In function `CPU::Main_body()':
: undefined reference to `psched::get_simper()'
/tmp/ccXpJn2d.o(.text+0xfc ): In function `CPU::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x11 3): In function `CPU::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x12 6): In function `CPU::Main_body()':
: undefined reference to `squeue::empty()'
/tmp/ccXpJn2d.o(.text+0x13 e): In function `CPU::Main_body()':
: undefined reference to `squeue::out()'
/tmp/ccXpJn2d.o(.text+0x17 b): In function `CPU::Main_body()':
: undefined reference to `process::delay(double)'
/tmp/ccXpJn2d.o(.text+0x1c 7): In function `CPU::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x25 f): In function `CPU::Main_body()':
: undefined reference to `process::reactivate()'
/tmp/ccXpJn2d.o(.text+0x26 9): In function `CPU::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x2a a): In function `CPU::Main_body()':
: undefined reference to `process::sleep()'
/tmp/ccXpJn2d.o(.text+0x2a f): In function `CPU::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x2c b): In function `CPU::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x33 5): In function `CPU::Main_body()':
: undefined reference to `process::terminate()'
/tmp/ccXpJn2d.o(.text+0x36 3): In function `job::job[not-in-charge](c har*, double, long)':
: undefined reference to `process::process[not-in-c harge](cha r*, objtype)'
/tmp/ccXpJn2d.o(.text+0x37 7): In function `job::job[not-in-charge](c har*, double, long)':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x3b 1): In function `job::job[not-in-charge](c har*, double, long)':
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0x3e d): In function `job::job[in-charge](char* , double, long)':
: undefined reference to `process::process[not-in-c harge](cha r*, objtype)'
/tmp/ccXpJn2d.o(.text+0x40 1): In function `job::job[in-charge](char* , double, long)':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x43 b): In function `job::job[in-charge](char* , double, long)':
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0x47 b): In function `job::set_start()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x51 5): In function `job::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x5a 2): In function `job::Main_body()':
: undefined reference to `squeue::full()'
/tmp/ccXpJn2d.o(.text+0x5f f): In function `job::Main_body()':
: undefined reference to `squeue::full()'
/tmp/ccXpJn2d.o(.text+0x64 a): In function `job::Main_body()':
: undefined reference to `process::terminate()'
/tmp/ccXpJn2d.o(.text+0x65 c): In function `job::Main_body()':
: undefined reference to `process::idle()'
/tmp/ccXpJn2d.o(.text+0x6a c): In function `job::Main_body()':
: undefined reference to `process::reactivate()'
/tmp/ccXpJn2d.o(.text+0x6b 9): In function `job::Main_body()':
: undefined reference to `squeue::full()'
/tmp/ccXpJn2d.o(.text+0x6d 5): In function `job::Main_body()':
: undefined reference to `squeue::into(process*)'
/tmp/ccXpJn2d.o(.text+0x71 6): In function `job::Main_body()':
: undefined reference to `process::sleep()'
/tmp/ccXpJn2d.o(.text+0x71 b): In function `job::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x76 7): In function `job::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x81 8): In function `job::Main_body()':
: undefined reference to `process::terminate()'
/tmp/ccXpJn2d.o(.text+0x84 7): In function `arrivals::arrivals[not-in -charge](c har*, double, double)':
: undefined reference to `process::process[not-in-c harge](cha r*, objtype)'
/tmp/ccXpJn2d.o(.text+0x88 3): In function `arrivals::arrivals[not-in -charge](c har*, double, double)':
: undefined reference to `erand::erand[in-charge](d ouble, unsigned)'
/tmp/ccXpJn2d.o(.text+0x8e 9): In function `arrivals::arrivals[not-in -charge](c har*, double, double)':
: undefined reference to `erand::erand[in-charge](d ouble, unsigned)'
/tmp/ccXpJn2d.o(.text+0x95 a): In function `arrivals::arrivals[not-in -charge](c har*, double, double)':
: undefined reference to `urand::urand[in-charge](l ong, long, unsigned)'
/tmp/ccXpJn2d.o(.text+0x9a 3): In function `arrivals::arrivals[not-in -charge](c har*, double, double)':
: undefined reference to `randint::seed(unsigned)'
/tmp/ccXpJn2d.o(.text+0xa1 4): In function `arrivals::arrivals[not-in -charge](c har*, double, double)':
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0xa5 5): In function `arrivals::arrivals[in-cha rge](char* , double, double)':
: undefined reference to `process::process[not-in-c harge](cha r*, objtype)'
/tmp/ccXpJn2d.o(.text+0xa9 1): In function `arrivals::arrivals[in-cha rge](char* , double, double)':
: undefined reference to `erand::erand[in-charge](d ouble, unsigned)'
/tmp/ccXpJn2d.o(.text+0xaf 7): In function `arrivals::arrivals[in-cha rge](char* , double, double)':
: undefined reference to `erand::erand[in-charge](d ouble, unsigned)'
/tmp/ccXpJn2d.o(.text+0xb6 8): In function `arrivals::arrivals[in-cha rge](char* , double, double)':
: undefined reference to `urand::urand[in-charge](l ong, long, unsigned)'
/tmp/ccXpJn2d.o(.text+0xbb 1): In function `arrivals::arrivals[in-cha rge](char* , double, double)':
: undefined reference to `randint::seed(unsigned)'
/tmp/ccXpJn2d.o(.text+0xc2 2): In function `arrivals::arrivals[in-cha rge](char* , double, double)':
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0xc6 5): In function `arrivals::Main_body()':
: undefined reference to `psched::get_simper()'
/tmp/ccXpJn2d.o(.text+0xc6 d): In function `arrivals::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0xc8 d): In function `arrivals::Main_body()':
: undefined reference to `erand::fdraw()'
/tmp/ccXpJn2d.o(.text+0xca 2): In function `arrivals::Main_body()':
: undefined reference to `process::delay(double)'
/tmp/ccXpJn2d.o(.text+0xca 7): In function `arrivals::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0xce 7): In function `arrivals::Main_body()':
: undefined reference to `process::terminate()'
/tmp/ccXpJn2d.o(.text+0xcf d): In function `arrivals::Main_body()':
: undefined reference to `erand::fdraw()'
/tmp/ccXpJn2d.o(.text+0xd1 4): In function `arrivals::Main_body()':
: undefined reference to `urand::draw()'
/tmp/ccXpJn2d.o(.text+0xd3 f): In function `arrivals::Main_body()':
: undefined reference to `intstr(int, char*)'
/tmp/ccXpJn2d.o(.text+0xdc 7): In function `arrivals::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0xe2 9): In function `arrivals::Main_body()':
: undefined reference to `process::pstart()'
/tmp/ccXpJn2d.o(.text+0xe5 9): In function `batch::batch[not-in-charg e](char*)' :
: undefined reference to `process::process[not-in-c harge](cha r*, objtype)'
/tmp/ccXpJn2d.o(.text+0xeb a): In function `batch::batch[not-in-charg e](char*)' :
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0xee f): In function `batch::batch[in-charge](c har*)':
: undefined reference to `process::process[not-in-c harge](cha r*, objtype)'
/tmp/ccXpJn2d.o(.text+0xf5 0): In function `batch::batch[in-charge](c har*)':
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0x10 41): In function `batch::Main_body()':
: undefined reference to `process::pstart()'
/tmp/ccXpJn2d.o(.text+0x10 4e): In function `batch::Main_body()':
: undefined reference to `process::pstart()'
/tmp/ccXpJn2d.o(.text+0x10 65): In function `batch::Main_body()':
: undefined reference to `simulation::start_sim(dou ble)'
/tmp/ccXpJn2d.o(.text+0x13 2a): In function `main':
: undefined reference to `simulation::simulation[in -charge](c har*)'
/tmp/ccXpJn2d.o(.text+0x13 8d): In function `main':
: undefined reference to `squeue::squeue[in-charge] (char*, int)'
/tmp/ccXpJn2d.o(.text+0x15 2f): In function `main':
: undefined reference to `process::pstart()'
/tmp/ccXpJn2d.o(.text+0x15 3c): In function `main':
: undefined reference to `simulation::end_sim()'
/tmp/ccXpJn2d.o(.gnu.linko nce.r._ZTI 3CPU+0x8): undefined reference to `typeinfo for process'
/tmp/ccXpJn2d.o(.gnu.linko nce.r._ZTI 3job+0x8): undefined reference to `typeinfo for process'
/tmp/ccXpJn2d.o(.gnu.linko nce.r._ZTI 8arrivals+ 0x8): undefined reference to `typeinfo for process'
/tmp/ccXpJn2d.o(.gnu.linko nce.r._ZTI 5batch+0x8 ): undefined reference to `typeinfo for process'
collect2: ld returned 1 exit status
a.out created.
I see that PThread.h is in the /usr/include directory, but it looks to me from the error messages that it is not finding the appropriate processes.
Here are the associated files:
script that does the compile/link:
clear
clear
echo '-------------------------
-------'
echo '------ Psim3 C++ (POSIX threads) package for object oriented simulation
-------'
# echo '------------------ (C) J. M. Garrido, 2004 -----------'
echo '-------------------------
-------'
g++ -w -pthread $1 /usr/psim3/libpsim3.a -I/usr/psim3 -lm
# the following are for bash and pdksh
#if [ "$2" != "" ] # change to parethesis for tcsh
#then
# mv a.out $2
# echo "$2 created."
#else
echo "a.out created."
#fi # change to endif fot tcsh
echo ' '
Here are the error messages:
--------------------------
------ Psim3 C++ (POSIX threads) package for object oriented simulation -------
--------------------------
/tmp/ccXpJn2d.o(.text+0x1d
: undefined reference to `process::process[not-in-c
/tmp/ccXpJn2d.o(.text+0x5d
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0x93
: undefined reference to `process::process[not-in-c
/tmp/ccXpJn2d.o(.text+0xd3
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0xf4
: undefined reference to `psched::get_simper()'
/tmp/ccXpJn2d.o(.text+0xfc
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x11
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x12
: undefined reference to `squeue::empty()'
/tmp/ccXpJn2d.o(.text+0x13
: undefined reference to `squeue::out()'
/tmp/ccXpJn2d.o(.text+0x17
: undefined reference to `process::delay(double)'
/tmp/ccXpJn2d.o(.text+0x1c
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x25
: undefined reference to `process::reactivate()'
/tmp/ccXpJn2d.o(.text+0x26
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x2a
: undefined reference to `process::sleep()'
/tmp/ccXpJn2d.o(.text+0x2a
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x2c
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x33
: undefined reference to `process::terminate()'
/tmp/ccXpJn2d.o(.text+0x36
: undefined reference to `process::process[not-in-c
/tmp/ccXpJn2d.o(.text+0x37
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x3b
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0x3e
: undefined reference to `process::process[not-in-c
/tmp/ccXpJn2d.o(.text+0x40
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x43
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0x47
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x51
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x5a
: undefined reference to `squeue::full()'
/tmp/ccXpJn2d.o(.text+0x5f
: undefined reference to `squeue::full()'
/tmp/ccXpJn2d.o(.text+0x64
: undefined reference to `process::terminate()'
/tmp/ccXpJn2d.o(.text+0x65
: undefined reference to `process::idle()'
/tmp/ccXpJn2d.o(.text+0x6a
: undefined reference to `process::reactivate()'
/tmp/ccXpJn2d.o(.text+0x6b
: undefined reference to `squeue::full()'
/tmp/ccXpJn2d.o(.text+0x6d
: undefined reference to `squeue::into(process*)'
/tmp/ccXpJn2d.o(.text+0x71
: undefined reference to `process::sleep()'
/tmp/ccXpJn2d.o(.text+0x71
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x76
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0x81
: undefined reference to `process::terminate()'
/tmp/ccXpJn2d.o(.text+0x84
: undefined reference to `process::process[not-in-c
/tmp/ccXpJn2d.o(.text+0x88
: undefined reference to `erand::erand[in-charge](d
/tmp/ccXpJn2d.o(.text+0x8e
: undefined reference to `erand::erand[in-charge](d
/tmp/ccXpJn2d.o(.text+0x95
: undefined reference to `urand::urand[in-charge](l
/tmp/ccXpJn2d.o(.text+0x9a
: undefined reference to `randint::seed(unsigned)'
/tmp/ccXpJn2d.o(.text+0xa1
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0xa5
: undefined reference to `process::process[not-in-c
/tmp/ccXpJn2d.o(.text+0xa9
: undefined reference to `erand::erand[in-charge](d
/tmp/ccXpJn2d.o(.text+0xaf
: undefined reference to `erand::erand[in-charge](d
/tmp/ccXpJn2d.o(.text+0xb6
: undefined reference to `urand::urand[in-charge](l
/tmp/ccXpJn2d.o(.text+0xbb
: undefined reference to `randint::seed(unsigned)'
/tmp/ccXpJn2d.o(.text+0xc2
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0xc6
: undefined reference to `psched::get_simper()'
/tmp/ccXpJn2d.o(.text+0xc6
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0xc8
: undefined reference to `erand::fdraw()'
/tmp/ccXpJn2d.o(.text+0xca
: undefined reference to `process::delay(double)'
/tmp/ccXpJn2d.o(.text+0xca
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0xce
: undefined reference to `process::terminate()'
/tmp/ccXpJn2d.o(.text+0xcf
: undefined reference to `erand::fdraw()'
/tmp/ccXpJn2d.o(.text+0xd1
: undefined reference to `urand::draw()'
/tmp/ccXpJn2d.o(.text+0xd3
: undefined reference to `intstr(int, char*)'
/tmp/ccXpJn2d.o(.text+0xdc
: undefined reference to `get_clock()'
/tmp/ccXpJn2d.o(.text+0xe2
: undefined reference to `process::pstart()'
/tmp/ccXpJn2d.o(.text+0xe5
: undefined reference to `process::process[not-in-c
/tmp/ccXpJn2d.o(.text+0xeb
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0xee
: undefined reference to `process::process[not-in-c
/tmp/ccXpJn2d.o(.text+0xf5
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccXpJn2d.o(.text+0x10
: undefined reference to `process::pstart()'
/tmp/ccXpJn2d.o(.text+0x10
: undefined reference to `process::pstart()'
/tmp/ccXpJn2d.o(.text+0x10
: undefined reference to `simulation::start_sim(dou
/tmp/ccXpJn2d.o(.text+0x13
: undefined reference to `simulation::simulation[in
/tmp/ccXpJn2d.o(.text+0x13
: undefined reference to `squeue::squeue[in-charge]
/tmp/ccXpJn2d.o(.text+0x15
: undefined reference to `process::pstart()'
/tmp/ccXpJn2d.o(.text+0x15
: undefined reference to `simulation::end_sim()'
/tmp/ccXpJn2d.o(.gnu.linko
/tmp/ccXpJn2d.o(.gnu.linko
/tmp/ccXpJn2d.o(.gnu.linko
/tmp/ccXpJn2d.o(.gnu.linko
collect2: ld returned 1 exit status
a.out created.
ASKER
Hey Corey,
Maybe this will help - here is the CPP file - proc.h and queue.h are in the same directory as the this file (batch.cpp) when i do the compile:
#include "proc.h"
#include "queue.h"
#include <string>
//
class CPU;
class job;
class arrivals;
//
squeue *job_queue; // queue for waiting jobs
// System parameters
const int qsize = 1120; // size of input queue
unsigned totmem = 40; // total system memory
//
// Workload parameters
double mean_int_arr; // mean inter-arrival period
double mean_ser; // mean service period
long mem_l; // lower bound for memory demand
long mem_u; // upper bound for memory demand
//
// Globals
double simperiod; // simulation period
double close_arrival; // time to stop
//
double time_mem = 0; // product time x memory
double acc_proc = 0; // accumulated processor time
unsigned arrived = 0; // number of arrived jobs
unsigned rejected = 0; // number of rejected jobs
double idle_time = 0; // acc processor idle time
double acc_sojourn_t = 0; // accumulated job sojourn time
double acc_wait = 0; // acc job wait time
unsigned completed_jobs = 0; // number of completed jobs
//
// Global object
CPU *proc; // processor
arrivals * arr_obj; // environment generating jobs
simulation * run;
//
// Specifications of processes
//
class CPU: public process {
// enum phasetype {RUN_JOB, COMPLETE_JOB, QUEUE_EMPTY, LEAVE_IDLE};
// phasetype phase;
job *curr_job; // job object
double start; // time of start of job
double job_time; // cpu time for job
public:
CPU(char *s); // constructor
void Main_body(void);
};
//
class job: public process {
// enum phasetype { ARRIVAL, FINISH_PROC };
// phasetype phase;
double arrival_time;
double start; // start of service
double jwait; // job wait time
double service; // job service service
long jmem; // job memory size
unsigned jobnum; // job number
public:
job(char *s, double ser, long mem);
double get_service(void);
long get_mem(void);
void set_start(void);
void Main_body(void);
};
//
class arrivals: public process {
// enum phasetype { INTER_ARRIVAL, NEW_ARRIVAL };
// phasetype phase;
erand *arr_period; // random inter-arrival period
erand *ser_period; // random job service
urand *jsize; // random job size
char *ss; // arrivals name
long memreq; // job memory requirements
public:
arrivals(char *s, double arr_mean, double ser_mean);
void Main_body(void);
};
//
// implementation of processes
//
CPU::CPU(char *s): process (s) {
// phase = RUN_JOB;
cout << "Processor object created" << endl;
};
//
void CPU::Main_body(void) {
double t_service;
double simper = get_simper();
long jmemreq;
// switch(phase) {
// cout << "Starting CPU Main_body " << endl;
while (get_clock() < simper) {
// case RUN_JOB:
start = get_clock();
if ( !job_queue->empty()) {
curr_job = ( job*) job_queue->out();
curr_job->set_start();
// phase = COMPLETE_JOB;
t_service = curr_job->get_service();
delay(t_service);
cout << "CPU completed service of Job " << curr_job->t_name << endl;
// case COMPLETE_JOB:
completed_jobs++;
job_time = get_clock() - start;
acc_proc += job_time;
jmemreq = curr_job->get_mem();
time_mem += jmemreq * job_time;
// cout << "Accumulated execution job time: " << acc_proc << endl;
if ( curr_job == NULL )
cout << "CPU with NULL Job " << endl;
else
curr_job->reactivate(); // delay(0);
}
else {
// queue_empty();
// void queue_empty() {
// case QUEUE_EMPTY:
cout << "CPU goes idle at " << get_clock() << endl;
// phase = LEAVE_IDLE;
sleep();
// break;
// case LEAVE_IDLE:
idle_time += get_clock() - start;
cout << "CPU is reactivated at " << get_clock() << endl;
// phase = RUN_JOB;
// break;
// }
// phase = QUEUE_EMPTY;
// break;
}
// phase = RUN_JOB;
// break;
} // endwhile
cout << "terminating CPU " << endl;
terminate();
};
//
// the constructor is called from 'arrivals'
job::job(char *s, double ser, long memreq): process (s) {
arrival_time = get_clock();
service = ser;
jmem = memreq;
arrived++;
// cout << t_name << " service time " << ser << " mem "
// << memreq << endl;
// phase = ARRIVAL;
};
//
double job :: get_service(void) {
return ( service );
};
//
long job :: get_mem(void) {
return ( jmem );
};
//
void job :: set_start(void) {
// this function sets the starting time of the job and displays
// the data (name, jobnum, clock time and service period)
start = get_clock();
cout << t_name << " starts service at "
<< start << " with service " << service << endl;
};
//
void job::Main_body(void) {
// switch(phase) {
// case ARRIVAL:
jobnum = arrived;
cout << t_name << " requiring service "
<< service << " arrives at time " << get_clock()
<< endl;
if ( jmem > totmem || job_queue->full() ) {
// there is not sufficient system memory for this job
// or the input queue is already full, reject
if(jmem > totmem)
cout << t_name << " rejected for memory " << endl;
if(job_queue->full())
cout << t_name << " rejected queue full " << endl;
rejected++;
terminate();
}
else {
if ( proc->idle() && proc != NULL ) {
cout << t_name << " reactivating CPU" << endl;
proc->reactivate(); // delay(0);
}
// job will wait in queue until processor executes it
if(! job_queue->full()) {
job_queue->into(this );
cout << t_name << " joins queue and waiting" << endl;
// phase = FINISH_PROC;
sleep(); // suspend or deactivate
// case FINISH_PROC:
// Service completed, prepare to exit system
acc_sojourn_t += ( ( get_clock()) - (arrival_time)) ;
jwait = (start) - (arrival_time);
// cout << t_name << " wait period " << jwait << endl;
acc_wait += jwait;
// display "Accumulated sojourn period: ", acc_sojourn_t;
cout << t_name << " terminates at time "
<< get_clock() << endl;
// resultis(0); delete (long *) this;
// break;
// }
}
else
cout << "Job queue full" << endl;
// break;
}
cout << "Terminating " << t_name << endl;
terminate();
};
//
arrivals::arrivals(char *s, double arr_mean, double ser_mean):
process (s) {
// create objects for random variables
arr_period = new erand (arr_mean, 7);
ser_period = new erand (ser_mean, 3);
jsize = new urand (mem_l, mem_u);
// initialize pseudo_random stream
// arr_period->seed(7);
// ser_period->seed(7);
jsize->seed(7);
//
// phase = INTER_ARRIVAL;
ss = s;
cout << "Arrivals created with " << arr_mean << " " << ser_mean << endl;
};
//
void arrivals::Main_body(void) {
double ttr;
int j = 0;
char numj[12];
char jobname[20] = "\0";
job *mjob;
double simper = get_simper(); // switch(phase) {
// cout << "Starting arrivals Main_body " << "Close arrival: "
// << close_arrival << endl;
while (get_clock() < simper) {
// generate random value for inter-arrival period
ttr = arr_period->fdraw();
// cout << "Inter-arrival: " << ttr << endl;
delay(ttr);
if ( get_clock() > close_arrival) {
cout << "Terminating arrivals " << endl;
terminate();
return;
}
else {
// generate random value for job service
ttr = ser_period->fdraw();
// generate random value for job size
memreq = jsize->draw();
// create job object with appropriate parameters
// cout << "Arrivals to create a new Job" << endl;
strcpy(jobname, "Job");
intstr(j, numj); // int to string numj
strcat(jobname, numj);
mjob = new job(jobname, ttr, memreq);
j++;
cout << "Arrivals generating " << jobname << " at " << get_clock() << endl;
mjob->pstart();
}
} // endwhile
};
//
class batch : public process {
public:
batch(char *);
void Main_body(void);
};
batch::batch(char *s) : process (s) {
cout << "Process " << s << " created" << endl;
};
//
void batch::Main_body(void) {
// cout << "In Main_body of: " << t_name << endl;
proc = new CPU("Processor");
arr_obj = new arrivals("Arrivals", mean_int_arr, mean_ser);
// cout << "Starting thread objects" << endl;
arr_obj->pstart(); // start arrivals object
//
proc->pstart();
//
run->start_sim(simperiod);
//
cout << endl << "Service factor: "
<< float(acc_proc) / float(acc_sojourn_t) << endl;
cout << "Processor utilization: "
<< float(acc_proc) / float(simperiod) << endl;
cout << "Total jobs arrived: " << arrived << endl;
cout << "Total jobs rejected: " << rejected << endl;
cout << "Throughput (jobs completed): " << completed_jobs << endl;
cout << "Proportion Rejected: "
<< ( float(rejected) / float(arrived)) << endl;
if ( completed_jobs > 0) {
cout << "Average job wait period: "
<< float(acc_wait) / float(completed_jobs) << endl;
}
cout << "Average memory used: "
<< float(time_mem) / float(simperiod) << endl;
};
//
int main() {
batch * application;
simperiod = 37380.0;
close_arrival = 37290.0;
mean_int_arr = 7.5;
mean_ser = 4.15;
mem_l = 8;
mem_u = 14;
run = new simulation("Simple Batch OS");
// create queue with default size qsize for incoming jobs
job_queue = new squeue ("cust");
//
application = new batch("Batch");
cout << "Workload parameters - mean inter-arrival: " << mean_int_arr
<< " mean CPU service demand: " << mean_ser << endl;
cout << " and memory demand: " << mem_l << " to " << mem_u << endl;
cout << "Systems parameters - queue capacity: " << qsize
<< " and system memory: " << totmem << endl;
//
application->pstart();
//
run->end_sim();
// cout << "Ending simulation" << endl;
return 0;
}
Maybe this will help - here is the CPP file - proc.h and queue.h are in the same directory as the this file (batch.cpp) when i do the compile:
#include "proc.h"
#include "queue.h"
#include <string>
//
class CPU;
class job;
class arrivals;
//
squeue *job_queue; // queue for waiting jobs
// System parameters
const int qsize = 1120; // size of input queue
unsigned totmem = 40; // total system memory
//
// Workload parameters
double mean_int_arr; // mean inter-arrival period
double mean_ser; // mean service period
long mem_l; // lower bound for memory demand
long mem_u; // upper bound for memory demand
//
// Globals
double simperiod; // simulation period
double close_arrival; // time to stop
//
double time_mem = 0; // product time x memory
double acc_proc = 0; // accumulated processor time
unsigned arrived = 0; // number of arrived jobs
unsigned rejected = 0; // number of rejected jobs
double idle_time = 0; // acc processor idle time
double acc_sojourn_t = 0; // accumulated job sojourn time
double acc_wait = 0; // acc job wait time
unsigned completed_jobs = 0; // number of completed jobs
//
// Global object
CPU *proc; // processor
arrivals * arr_obj; // environment generating jobs
simulation * run;
//
// Specifications of processes
//
class CPU: public process {
// enum phasetype {RUN_JOB, COMPLETE_JOB, QUEUE_EMPTY, LEAVE_IDLE};
// phasetype phase;
job *curr_job; // job object
double start; // time of start of job
double job_time; // cpu time for job
public:
CPU(char *s); // constructor
void Main_body(void);
};
//
class job: public process {
// enum phasetype { ARRIVAL, FINISH_PROC };
// phasetype phase;
double arrival_time;
double start; // start of service
double jwait; // job wait time
double service; // job service service
long jmem; // job memory size
unsigned jobnum; // job number
public:
job(char *s, double ser, long mem);
double get_service(void);
long get_mem(void);
void set_start(void);
void Main_body(void);
};
//
class arrivals: public process {
// enum phasetype { INTER_ARRIVAL, NEW_ARRIVAL };
// phasetype phase;
erand *arr_period; // random inter-arrival period
erand *ser_period; // random job service
urand *jsize; // random job size
char *ss; // arrivals name
long memreq; // job memory requirements
public:
arrivals(char *s, double arr_mean, double ser_mean);
void Main_body(void);
};
//
// implementation of processes
//
CPU::CPU(char *s): process (s) {
// phase = RUN_JOB;
cout << "Processor object created" << endl;
};
//
void CPU::Main_body(void) {
double t_service;
double simper = get_simper();
long jmemreq;
// switch(phase) {
// cout << "Starting CPU Main_body " << endl;
while (get_clock() < simper) {
// case RUN_JOB:
start = get_clock();
if ( !job_queue->empty()) {
curr_job = ( job*) job_queue->out();
curr_job->set_start();
// phase = COMPLETE_JOB;
t_service = curr_job->get_service();
delay(t_service);
cout << "CPU completed service of Job " << curr_job->t_name << endl;
// case COMPLETE_JOB:
completed_jobs++;
job_time = get_clock() - start;
acc_proc += job_time;
jmemreq = curr_job->get_mem();
time_mem += jmemreq * job_time;
// cout << "Accumulated execution job time: " << acc_proc << endl;
if ( curr_job == NULL )
cout << "CPU with NULL Job " << endl;
else
curr_job->reactivate(); // delay(0);
}
else {
// queue_empty();
// void queue_empty() {
// case QUEUE_EMPTY:
cout << "CPU goes idle at " << get_clock() << endl;
// phase = LEAVE_IDLE;
sleep();
// break;
// case LEAVE_IDLE:
idle_time += get_clock() - start;
cout << "CPU is reactivated at " << get_clock() << endl;
// phase = RUN_JOB;
// break;
// }
// phase = QUEUE_EMPTY;
// break;
}
// phase = RUN_JOB;
// break;
} // endwhile
cout << "terminating CPU " << endl;
terminate();
};
//
// the constructor is called from 'arrivals'
job::job(char *s, double ser, long memreq): process (s) {
arrival_time = get_clock();
service = ser;
jmem = memreq;
arrived++;
// cout << t_name << " service time " << ser << " mem "
// << memreq << endl;
// phase = ARRIVAL;
};
//
double job :: get_service(void) {
return ( service );
};
//
long job :: get_mem(void) {
return ( jmem );
};
//
void job :: set_start(void) {
// this function sets the starting time of the job and displays
// the data (name, jobnum, clock time and service period)
start = get_clock();
cout << t_name << " starts service at "
<< start << " with service " << service << endl;
};
//
void job::Main_body(void) {
// switch(phase) {
// case ARRIVAL:
jobnum = arrived;
cout << t_name << " requiring service "
<< service << " arrives at time " << get_clock()
<< endl;
if ( jmem > totmem || job_queue->full() ) {
// there is not sufficient system memory for this job
// or the input queue is already full, reject
if(jmem > totmem)
cout << t_name << " rejected for memory " << endl;
if(job_queue->full())
cout << t_name << " rejected queue full " << endl;
rejected++;
terminate();
}
else {
if ( proc->idle() && proc != NULL ) {
cout << t_name << " reactivating CPU" << endl;
proc->reactivate(); // delay(0);
}
// job will wait in queue until processor executes it
if(! job_queue->full()) {
job_queue->into(this );
cout << t_name << " joins queue and waiting" << endl;
// phase = FINISH_PROC;
sleep(); // suspend or deactivate
// case FINISH_PROC:
// Service completed, prepare to exit system
acc_sojourn_t += ( ( get_clock()) - (arrival_time)) ;
jwait = (start) - (arrival_time);
// cout << t_name << " wait period " << jwait << endl;
acc_wait += jwait;
// display "Accumulated sojourn period: ", acc_sojourn_t;
cout << t_name << " terminates at time "
<< get_clock() << endl;
// resultis(0); delete (long *) this;
// break;
// }
}
else
cout << "Job queue full" << endl;
// break;
}
cout << "Terminating " << t_name << endl;
terminate();
};
//
arrivals::arrivals(char *s, double arr_mean, double ser_mean):
process (s) {
// create objects for random variables
arr_period = new erand (arr_mean, 7);
ser_period = new erand (ser_mean, 3);
jsize = new urand (mem_l, mem_u);
// initialize pseudo_random stream
// arr_period->seed(7);
// ser_period->seed(7);
jsize->seed(7);
//
// phase = INTER_ARRIVAL;
ss = s;
cout << "Arrivals created with " << arr_mean << " " << ser_mean << endl;
};
//
void arrivals::Main_body(void) {
double ttr;
int j = 0;
char numj[12];
char jobname[20] = "\0";
job *mjob;
double simper = get_simper(); // switch(phase) {
// cout << "Starting arrivals Main_body " << "Close arrival: "
// << close_arrival << endl;
while (get_clock() < simper) {
// generate random value for inter-arrival period
ttr = arr_period->fdraw();
// cout << "Inter-arrival: " << ttr << endl;
delay(ttr);
if ( get_clock() > close_arrival) {
cout << "Terminating arrivals " << endl;
terminate();
return;
}
else {
// generate random value for job service
ttr = ser_period->fdraw();
// generate random value for job size
memreq = jsize->draw();
// create job object with appropriate parameters
// cout << "Arrivals to create a new Job" << endl;
strcpy(jobname, "Job");
intstr(j, numj); // int to string numj
strcat(jobname, numj);
mjob = new job(jobname, ttr, memreq);
j++;
cout << "Arrivals generating " << jobname << " at " << get_clock() << endl;
mjob->pstart();
}
} // endwhile
};
//
class batch : public process {
public:
batch(char *);
void Main_body(void);
};
batch::batch(char *s) : process (s) {
cout << "Process " << s << " created" << endl;
};
//
void batch::Main_body(void) {
// cout << "In Main_body of: " << t_name << endl;
proc = new CPU("Processor");
arr_obj = new arrivals("Arrivals", mean_int_arr, mean_ser);
// cout << "Starting thread objects" << endl;
arr_obj->pstart(); // start arrivals object
//
proc->pstart();
//
run->start_sim(simperiod);
//
cout << endl << "Service factor: "
<< float(acc_proc) / float(acc_sojourn_t) << endl;
cout << "Processor utilization: "
<< float(acc_proc) / float(simperiod) << endl;
cout << "Total jobs arrived: " << arrived << endl;
cout << "Total jobs rejected: " << rejected << endl;
cout << "Throughput (jobs completed): " << completed_jobs << endl;
cout << "Proportion Rejected: "
<< ( float(rejected) / float(arrived)) << endl;
if ( completed_jobs > 0) {
cout << "Average job wait period: "
<< float(acc_wait) / float(completed_jobs) << endl;
}
cout << "Average memory used: "
<< float(time_mem) / float(simperiod) << endl;
};
//
int main() {
batch * application;
simperiod = 37380.0;
close_arrival = 37290.0;
mean_int_arr = 7.5;
mean_ser = 4.15;
mem_l = 8;
mem_u = 14;
run = new simulation("Simple Batch OS");
// create queue with default size qsize for incoming jobs
job_queue = new squeue ("cust");
//
application = new batch("Batch");
cout << "Workload parameters - mean inter-arrival: " << mean_int_arr
<< " mean CPU service demand: " << mean_ser << endl;
cout << " and memory demand: " << mem_l << " to " << mem_u << endl;
cout << "Systems parameters - queue capacity: " << qsize
<< " and system memory: " << totmem << endl;
//
application->pstart();
//
run->end_sim();
// cout << "Ending simulation" << endl;
return 0;
}
It looks like you are not compiling a lot of needed .cpp files along with batch.cpp such as proc.cpp/etc.
You need to add these source files to your compile command and then link.
corey
You need to add these source files to your compile command and then link.
corey
ASKER
""t looks like you are not compiling a lot of needed .cpp files along with batch.cpp such as proc.cpp/etc.
You need to add these source files to your compile command and then link."
Hey Corey - i know this is a stupid question, but how do I do that? I do not have the proc.cpp files. All i have are the header files proc.h.
When i do compile only it works fine. it is when i try to link everything that it crashes.
i am using "-lpthread" in my g++ command line, so it should be linking to the pthread library..... this works fine on a RedHat system - i just don't understand why it is not working on my Knoppix (Debian) system
You need to add these source files to your compile command and then link."
Hey Corey - i know this is a stupid question, but how do I do that? I do not have the proc.cpp files. All i have are the header files proc.h.
When i do compile only it works fine. it is when i try to link everything that it crashes.
i am using "-lpthread" in my g++ command line, so it should be linking to the pthread library..... this works fine on a RedHat system - i just don't understand why it is not working on my Knoppix (Debian) system
proc.h is a file that you or someone in your team created right? If it is in your source directory, that is what I was assuming.
Apparantly, it is a base class, and you're deriving from it. Because of that, you also need to link in the implementation of process.
If this is part of a standard library, please specify. The pthread library only includes pthread calls, not your other source code.
To add source files, you simply append them to your compilation command
g++ -I/some/dir/include -o MyExecutable Source1.cpp Source2.cpp Source3.cpp -lm -lpthread
corey
Apparantly, it is a base class, and you're deriving from it. Because of that, you also need to link in the implementation of process.
If this is part of a standard library, please specify. The pthread library only includes pthread calls, not your other source code.
To add source files, you simply append them to your compilation command
g++ -I/some/dir/include -o MyExecutable Source1.cpp Source2.cpp Source3.cpp -lm -lpthread
corey
ASKER
Well, unfortunately, it is not a program that i wrote or that a team member wrote.
A professor at my university wrote it and like an idiot i took on a project to write a web page "wrapper" around this program. My first step is just to get the stupid thing to compile under debian linux.
My professor is being complelely un-helpful ....... his answer: "it works on my red hat box here"
So i am stuck trying to figure this out on my own.
There is a library file called "libpsim3.a" - inside of it there are a bunch of .o files like "proc.o"
So i have the compiled versions that the header files point to.
This is the command I am using to compile/link:
g++ -w -I/usr/psim3 -o gobatch batch.cpp -lm -lpthread
So it looks like i have all the files i need i just can't figure out why it won't properly link them in....
A professor at my university wrote it and like an idiot i took on a project to write a web page "wrapper" around this program. My first step is just to get the stupid thing to compile under debian linux.
My professor is being complelely un-helpful ....... his answer: "it works on my red hat box here"
So i am stuck trying to figure this out on my own.
There is a library file called "libpsim3.a" - inside of it there are a bunch of .o files like "proc.o"
So i have the compiled versions that the header files point to.
This is the command I am using to compile/link:
g++ -w -I/usr/psim3 -o gobatch batch.cpp -lm -lpthread
So it looks like i have all the files i need i just can't figure out why it won't properly link them in....
ASKER
I should clarify - i extracted the .o files out into the directory i am compiling in which is "/usr/psim3"
Also, i did try using "g++ -w batch.cpp /usr/psim3/libpsim3.a -I/usr/psim3 -lm -lpthread
Also, i did try using "g++ -w batch.cpp /usr/psim3/libpsim3.a -I/usr/psim3 -lm -lpthread
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey Corey,
It is still not working. I am going to change my project a little bit as the professor is not being very helpful.
I can edit/compile the program on his machine, so I will just modify the programs to take parameters from the command line. I can then compile it on his box and just copy the executables to my box. I wanted to be able to recompile on the fly, but i will just tell him that will be a phase 2 project if he wants that and he will have to give me access to all the source files so i can recompile everything from scratch.
I am still getting the same messages:
root@600x:/usr/psim3# g++ -I/usr/psim3 -L/usr/psim3 -o gobatch batch.cpp -lm -lpthread -lpsim3
In file included from /usr/include/c++/3.3/backw ard/iostre am.h:31,
from proc.h:13,
from batch.cpp:13:
/usr/include/c++/3.3/backw ard/backwa rd_warning .h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
/tmp/ccf7azU5.o(.text+0x1d ): In function `CPU::CPU[not-in-charge](c har*)':
: undefined reference to `process::process[not-in-c harge](cha r*, objtype)'
/tmp/ccf7azU5.o(.text+0x5d ): In function `CPU::CPU[not-in-charge](c har*)':
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccf7azU5.o(.text+0x93 ): In function `CPU::CPU[in-charge](char* )':
: undefined reference to `process::process[not-in-c harge](cha r*, objtype)'
/tmp/ccf7azU5.o(.text+0xd3 ): In function `CPU::CPU[in-charge](char* )':
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccf7azU5.o(.text+0xf4 ): In function `CPU::Main_body()':
: undefined reference to `psched::get_simper()'
/tmp/ccf7azU5.o(.text+0xfc ): In function `CPU::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccf7azU5.o(.text+0x11 3): In function `CPU::Main_body()':
: undefined reference to `get_clock()'
/tmp/ccf7azU5.o(.text+0x12 6): In function `CPU::Main_body()':
: undefined reference to `squeue::empty()'
/tmp/ccf7azU5.o(.text+0x13 e): In function `CPU::Main_body()':
: undefined reference to `squeue::out()'
..... and more......
It is still not working. I am going to change my project a little bit as the professor is not being very helpful.
I can edit/compile the program on his machine, so I will just modify the programs to take parameters from the command line. I can then compile it on his box and just copy the executables to my box. I wanted to be able to recompile on the fly, but i will just tell him that will be a phase 2 project if he wants that and he will have to give me access to all the source files so i can recompile everything from scratch.
I am still getting the same messages:
root@600x:/usr/psim3# g++ -I/usr/psim3 -L/usr/psim3 -o gobatch batch.cpp -lm -lpthread -lpsim3
In file included from /usr/include/c++/3.3/backw
from proc.h:13,
from batch.cpp:13:
/usr/include/c++/3.3/backw
/tmp/ccf7azU5.o(.text+0x1d
: undefined reference to `process::process[not-in-c
/tmp/ccf7azU5.o(.text+0x5d
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccf7azU5.o(.text+0x93
: undefined reference to `process::process[not-in-c
/tmp/ccf7azU5.o(.text+0xd3
: undefined reference to `process::~process [not-in-charge]()'
/tmp/ccf7azU5.o(.text+0xf4
: undefined reference to `psched::get_simper()'
/tmp/ccf7azU5.o(.text+0xfc
: undefined reference to `get_clock()'
/tmp/ccf7azU5.o(.text+0x11
: undefined reference to `get_clock()'
/tmp/ccf7azU5.o(.text+0x12
: undefined reference to `squeue::empty()'
/tmp/ccf7azU5.o(.text+0x13
: undefined reference to `squeue::out()'
..... and more......
ASKER
Corey,
Even though we didn't get this one solved i'm going to give you the points anyway because I now understand the compile/linking process on Linux a lot better than I did before......... i haven't done command line compile/link since i was a PASCAL programmer back in the late 1980's!!! Funny how quickly we get spoiled with IDEs :))
Even though we didn't get this one solved i'm going to give you the points anyway because I now understand the compile/linking process on Linux a lot better than I did before......... i haven't done command line compile/link since i was a PASCAL programmer back in the late 1980's!!! Funny how quickly we get spoiled with IDEs :))
Well, however you score it and award points I'm just hear to help if I can.
It seems to me that the library (.a file) that he made is missing an object file or two. There's no reason for it to not link parts of the library if they objects do indeed exist in there.
Here is the official GCC documentation. Some of it is a little obtuse, but it has all the command options.
The output options such as -o are in the "Overall Options" link and you can find the others.
http://gcc.gnu.org/onlinedocs/gcc-3.4.3/gcc/Invoking-GCC.html#Invoking-GCC ["GCC Command Options"]
corey
It seems to me that the library (.a file) that he made is missing an object file or two. There's no reason for it to not link parts of the library if they objects do indeed exist in there.
Here is the official GCC documentation. Some of it is a little obtuse, but it has all the command options.
The output options such as -o are in the "Overall Options" link and you can find the others.
http://gcc.gnu.org/onlinedocs/gcc-3.4.3/gcc/Invoking-GCC.html#Invoking-GCC ["GCC Command Options"]
corey
The reason for this is missing object files or libraries. The only thing I see you adding in that compilation is libpsim3.a . Are you sure this is supposed to contain all the objects that you see are missing in that error list?
corey