0

I am working on a shceduler program designed to take in multiple processes, assign them an id, priority number, and burst time, then add them to a queue. a scheduler will call these processes, print out their information (i.e id, time in system...), then delist/ pop them off the queue)

when I try to compile and run it, I get several linker errors which I have attatched at the bottom after the code. I have a node header, node implementation, queue header, queue implementation, a scheduler header and implementation (which contains my main function), and process header, and implementation. the process file creates information for each process (i.e the id, priority number, burst time, etc.) and the shceduler function pushes/enlists them in a queue, calls them out the queue, prints out their information, and pops/delists them off the queue.

As mentioned earlier the main function is in the header file

node header

#ifndef MAIN_SAVITCH_NODE2_H
#define MAIN_SAVITCH_NODE2_H
#include <cstdlib> 
#include <iterator> 
namespace main_savitch_8C
{
    template <class Item>
    class node
    {
    public:
        typedef Item value_type;
        node(const Item& init_data = Item(), node* init_link = NULL)
        {
            data_field = init_data; link_field = init_link;
        }
        Item& data() { return data_field; }
        node* link() { return link_field; }
        void set_data(const Item& new_data)
        {
            data_field = new_data;
        }
        void set_link(node* new_link) { link_field = new_link; }
        const Item& data()
            const {
            return data_field;
        }
        const node* link()
            const {
            return link_field;
        }
    private:
        Item data_field;
        node* link_field;
    };
    template <class Item>
    void list_clear(node<Item>*& head_ptr);
    template <class NodePtr, class Item>
    NodePtr list_search(NodePtr head_ptr, const Item& target);
    template <class Item>
    void list_copy(const node<Item>* source_ptr, node<Item>*& head_ptr, node<Item>*& tail_ptr);
    template <class Item>
    void list_head_insert(node<Item>*& head_ptr, const Item& entry);
    template <class Item>
    void list_head_remove(node<Item>*& head_ptr);
    template <class Item>
    void list_insert(node<Item>* previous_ptr, const Item& entry);
    template <class Item>
    std::size_t list_length(const node<Item>* head_ptr);
    template <class NodePtr, class SizeType>
    NodePtr list_locate(NodePtr head_ptr, SizeType position);
    template <class Item>
    void list_remove(node<Item>* previous_ptr);
    template <class NodePtr, class Item>
    NodePtr list_search(NodePtr head_ptr, const Item& target);
}
#include "node2.template"
#endif

node template

#include <cassert>    // Provides assert
#include <cstdlib>    // Provides NULL and size_t

namespace main_savitch_8C
{
    template <class Item>
    void list_clear(node<Item>*& head_ptr)
    // Library facilities used: cstdlib
    {
    while (head_ptr != NULL)
        list_head_remove(head_ptr);
    }

    template <class Item>
    void list_copy(
    const node<Item>* source_ptr,
    node<Item>*& head_ptr,
    node<Item>*& tail_ptr
    ) 
    // Library facilities used: cstdlib
    {
    head_ptr = NULL;
    tail_ptr = NULL;

    // Handle the case of the empty list
    if (source_ptr == NULL)
        return; 

    // Make the head node for the newly created list, and put data in it
    list_head_insert(head_ptr, source_ptr->data( ));
    tail_ptr = head_ptr; 
    
    // Copy rest of the nodes one at a time, adding at the tail of new list
    source_ptr = source_ptr->link( ); 
        while (source_ptr != NULL)
    {
        list_insert(tail_ptr, source_ptr->data( ));
        tail_ptr = tail_ptr->link( );
        source_ptr = source_ptr->link( );
    }
    }
    
    template <class Item>
    void list_head_insert(node<Item>*& head_ptr, const Item& entry)
    {
    head_ptr = new node<Item>(entry, head_ptr);
    }

    template <class Item>
    void list_head_remove(node<Item>*& head_ptr)
    {
    node<Item> *remove_ptr;

    remove_ptr = head_ptr;
    head_ptr = head_ptr->link( );
    delete remove_ptr;
    }

    template <class Item>
    void list_insert(node<Item>* previous_ptr, const Item& entry) 
    {
    node<Item> *insert_ptr;
    
    insert_ptr = new node<Item>(entry, previous_ptr->link( ));
    previous_ptr->set_link(insert_ptr);
    }

    template <class Item>
    std::size_t list_length(const node<Item>* head_ptr)
    // Library facilities used: cstdlib
    {
    const node<Item> *cursor;
    std::size_t answer;
    
    answer = 0;
    for (cursor = head_ptr; cursor != NULL; cursor = cursor->link( ))
        ++answer;
    
    return answer;
    }

    template <class NodePtr, class SizeType>
    NodePtr list_locate(NodePtr head_ptr, SizeType position) 
    // Library facilities used: cassert, cstdlib
    {
    NodePtr cursor;
    SizeType i;
    
    assert(0 < position);
    cursor = head_ptr;
    for (i = 1; (i < position) && (cursor != NULL); ++i)
        cursor = cursor->link( );
    return cursor;
    }

    template <class Item>
    void list_remove(node<Item>* previous_ptr)
    {
    node<Item> *remove_ptr;

    remove_ptr = previous_ptr->link( );
    previous_ptr->set_link(remove_ptr->link( ));
    delete remove_ptr;
    }

    template <class NodePtr, class Item>
    NodePtr list_search(NodePtr head_ptr, const Item& target) 
    // Library facilities used: cstdlib
    {
    NodePtr cursor;
    
    for (cursor = head_ptr; cursor != NULL; cursor = cursor->link( ))
        if (target == cursor->data( ))
        return cursor;
    return NULL;
    }
}

queue header

#ifndef MAIN_SAVITCH_QUEUE2_H     // Prevent duplicate definition
#define MAIN_SAVITCH_QUEUE2_H
#include <cstdlib>   // Provides std::size_t
#include "node2.h"   // Node template class

namespace main_savitch_8C
{
    template <class Item>
    class queue
    {
    public:
        // TYPEDEFS 
        typedef std::size_t size_type;
        typedef Item value_type;
        // CONSTRUCTORS and DESTRUCTOR
        queue();
        queue(const queue<Item>& source);
        ~queue();
        // MODIFICATION MEMBER FUNCTIONS
        void pop();
        void push(const Item& entry);
        void operator =(const queue<Item>& source);
        // CONSTANT MEMBER FUNCTIONS
        bool empty() const { return (count == 0); }
        Item front() const;
        size_type size() const { return count; }
    private:
        main_savitch_6B::node<Item>* front_ptr;
        main_savitch_6B::node<Item>* rear_ptr;
        size_type count;       // Total number of items in the queue
    };
}
#include "queue2.template" // Include the implementation

#endif

queue template

#include <cassert>   // Provides assert
#include "node2.h"   // Node template class

namespace main_savitch_8C
{
    template <class Item>
    queue<Item>::queue( )
    {
        count = 0;
        front_ptr = NULL;
    }

    template <class Item>
    queue<Item>::queue(const queue<Item>& source)
    // Library facilities used: node2.h
    {
    count = source.count;
    list_copy(source.front_ptr, front_ptr, rear_ptr);
    }

    template <class Item>
    queue<Item>::~queue( )
    {
        list_clear(front_ptr);
    }

    template <class Item>
    void queue<Item>::operator =(const queue<Item>& source)
    // Library facilities used: node2.h
    {
        if (this == &source) // Handle self-assignment
            return;
        list_clear(front_ptr);
        list_copy(source.front_ptr, front_ptr, rear_ptr);
        count = source.count;
    }

    template <class Item>
    Item queue<Item>::front( ) const
    // Library facilities used: cassert
    {
        assert(!empty( ));    
        return front_ptr->data( );
    }
    
    template <class Item>
    void queue<Item>::pop( )
    // Library facilities used: cassert, node2.h
    {
        assert(!empty( ));
    list_head_remove(front_ptr);
    --count;
    }
    
    template <class Item>
    void queue<Item>::push(const Item& entry)
    // Library facilities used: node2.h
    {
        if (empty( ))
        {   // Insert first entry.
            list_head_insert(front_ptr, entry);
            rear_ptr = front_ptr;
        }
        else
        {   // Insert an entry that is not the first.
            list_insert(rear_ptr, entry);
            rear_ptr = rear_ptr->link( );
        }
        ++count;
    }

}

process header

#ifndef MAIN_SAVITCH_PROCESS_H
#define MAIN_SAVITCH_PROCESS_H

namespace main_savitch_8C
{
    class process
    {
    public:


        double arrival_time;
        int waiting_time;
        double service_time;
        int id;
        int priority_number;
        int order;
        static int nextid;
        static int nextpri;
        double totaltime;
        process(int comp);
        process();

        void arrival();
        int waiting_times();
        void time_insystem();


    };
}
#endif

process implementation

#include <cstdlib>
#include <iostream>
#include <random>
#include "Process.h"


namespace main_savitch_8C
{
    process::process(int comp)
    {

        waiting_time = (rand() % 2400) + 1;
        service_time = (rand() % 2400) + 1;
        if (waiting_time > service_time)
        {
            arrival_time = (rand() % (int)service_time);
        }
        else
        {
            arrival_time = (rand() % waiting_time);
        }
        nextid = 0;
        id = nextid++;
        nextpri = 0;
        priority_number = nextpri++;
        order = comp;
        totaltime = 0;
    }

    process::process()
    {

    }
    int process::waiting_times()
    {
        return waiting_time;
    }
    void process::time_insystem()
    {
        totaltime = (service_time + waiting_time - arrival_time);
    }
}

scheduler header


#ifndef MAIN_SAVITCH_SCHEDULER_H
#define MAIN_SAVITCH_SCHEDULER_H
#include "Process.h"
#include "node.h"
#include "queue2.h"
/*#include "queue.template"*/

namespace main_savitch_8C
{
    class scheduler
    {
    private:
        int queuelength;
    public:

        scheduler();
        queue<process> pqueue;
        void enlist(process p);
        void delist(process  p);
        int set_priority(process p);
        void schedule(process p);
        size_t list_length();
        void statistician();
    };
}
//#include "scheduler.cpp"

#endif

scheduler implemetation. includes main

#include <cstdlib>
#include <iostream>
#include "queue2.h"
#include "Scheduler.h"
#include "node.h"
#include "Process.h"


namespace main_savitch_8C
{
    scheduler::scheduler()
    {

    }

    void scheduler::enlist(process q)
    {
        pqueue.push(q);
    }

    void scheduler::delist(process q)
    {
        pqueue.pop();
    }

    int scheduler::set_priority(process q)
    {
        return q.priority_number;
    }

    void scheduler::schedule(process q)
    {
        cout << pqueue.front().id << endl;
        cout << pqueue.front().totaltime << endl;
        cout << pqueue.front().priority_number << endl;
    }


    int main()
    {
        int s;
        scheduler nsched;
        process q = process();
        for (s = 0; s < 1000; s++)
        {
            q = process(s);
            nsched.enlist(q);
            q.totaltime;
            nsched.schedule(q);
            nsched.delist(q);

        }
        return 0;
    }
}

here are the errors I am recieving

LNK2001 

unresolved external symbol "public: static int main_savitch_8C::process::nextid" (?nextid@process@main_savitch_8C@@2HA) 



LNK2001 

unresolved external symbol "public: static int main_savitch_8C::process::nextpri" (?nextpri@process@main_savitch_8C@@2HA)   



LNK2019 

unresolved external symbol "void __cdecl list_clear<class main_savitch_8C::process>(class node<class main_savitch_8C::process> * &)" (??$list_clear@Vprocess@main_savitch_8C@@@@YAXAAPAV?$node@Vprocess@main_savitch_8C@@@@@Z) referenced in function "public: __thiscall queue<class main_savitch_8C::process>::~queue<class main_savitch_8C::process>(void)" (??1?$queue@Vprocess@main_savitch_8C@@@@QAE@XZ)  




LNK2019 

unresolved external symbol "void __cdecl list_head_remove<class main_savitch_8C::process>(class node<class main_savitch_8C::process> * &)" (??$list_head_remove@Vprocess@main_savitch_8C@@@@YAXAAPAV?$node@Vprocess@main_savitch_8C@@@@@Z) referenced in function "public: void __thiscall queue<class main_savitch_8C::process>::pop(void)" (?pop@?$queue@Vprocess@main_savitch_8C@@@@QAEXXZ)  




LNK2019 

unresolved external symbol "void __cdecl list_head_insert<class main_savitch_8C::process>(class node<class main_savitch_8C::process> * &,class main_savitch_8C::process const &)" (??$list_head_insert@Vprocess@main_savitch_8C@@@@YAXAAPAV?$node@Vprocess@main_savitch_8C@@@@ABVprocess@main_savitch_8C@@@Z) referenced in function "public: void __thiscall queue<class main_savitch_8C::process>::push(class main_savitch_8C::process const &)" (?push@?$queue@Vprocess@main_savitch_8C@@@@QAEXABVprocess@main_savitch_8C@@@Z)



LNK2019 

unresolved external symbol "void __cdecl list_insert<class main_savitch_8C::process>(class node<class main_savitch_8C::process> *,class main_savitch_8C::process const &)" (??$list_insert@Vprocess@main_savitch_8C@@@@YAXPAV?$node@Vprocess@main_savitch_8C@@@@ABVprocess@main_savitch_8C@@@Z) referenced in function "public: void __thiscall queue<class main_savitch_8C::process>::push(class main_savitch_8C::process const &)" (?push@?$queue@Vprocess@main_savitch_8C@@@@QAEXABVprocess@main_savitch_8C@@@Z) 


LNK2019 

unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)   



LNK1120 

7 unresolved externals  
Alan Birtles
  • 32,622
  • 4
  • 31
  • 60

0 Answers0