-1

I have multiple c++ class files and header files when i attempt to compile them i get the following error.I even tried using cmake to make my life easier but i still get it:

make: Warning: File `Makefile' has modification time 11 s in the future
make[1]: Warning: File `CMakeFiles/Makefile2' has modification time 11 s in the future
make[2]: Warning: File `src/CMakeFiles/simulation.dir/flags.make' has modification time 11 s in the future
Scanning dependencies of target simulation
make[2]: warning:  Clock skew detected.  Your build may be incomplete.
make[2]: Warning: File `src/CMakeFiles/simulation.dir/flags.make' has modification time 11 s in the future
[  4%] Building CXX object src/CMakeFiles/simulation.dir/OS.cxx.o
[  9%] Building CXX object src/CMakeFiles/simulation.dir/Ram.cxx.o
[ 14%] Building CXX object src/CMakeFiles/simulation.dir/RamQueues.cxx.o
[ 19%] Building CXX object src/CMakeFiles/simulation.dir/HardDisk.cxx.o
[ 23%] Building CXX object src/CMakeFiles/simulation.dir/CpuRegisters.cxx.o
[ 28%] Building CXX object src/CMakeFiles/simulation.dir/BankersAlgorithm.cxx.o
[ 33%] Building CXX object src/CMakeFiles/simulation.dir/Clock.cxx.o
[ 38%] Building CXX object src/CMakeFiles/simulation.dir/random.cxx.o
[ 42%] Building CXX object src/CMakeFiles/simulation.dir/PCB.cxx.o
[ 47%] Building CXX object src/CMakeFiles/simulation.dir/File.cxx.o
[ 52%] Building CXX object src/CMakeFiles/simulation.dir/Jobs.cxx.o
[ 57%] Building CXX object src/CMakeFiles/simulation.dir/Cpu.cxx.o
[ 61%] Building CXX object src/CMakeFiles/simulation.dir/JobCreationFactory.cxx.o
[ 66%] Building CXX object src/CMakeFiles/simulation.dir/StateQueue.cxx.o
[ 71%] Building CXX object src/CMakeFiles/simulation.dir/Keyboard.cxx.o
[ 76%] Building CXX object src/CMakeFiles/simulation.dir/Mouse.cxx.o
[ 80%] Building CXX object src/CMakeFiles/simulation.dir/Monitor.cxx.o
[ 85%] Building CXX object src/CMakeFiles/simulation.dir/ReadyQueue.cxx.o
[ 90%] Building CXX object src/CMakeFiles/simulation.dir/TerminatingQueue.cxx.o
[ 95%] Building CXX object src/CMakeFiles/simulation.dir/WaitingQueue.cxx.o
[100%] Building CXX object src/CMakeFiles/simulation.dir/osTester.cxx.o
Linking CXX executable simulation
CMakeFiles/simulation.dir/osTester.cxx.o: In function `main':
osTester.cxx:(.text+0xa3): undefined reference to `JobCreationFactory::createFiles(HardDisk)'
osTester.cxx:(.text+0xb9): undefined reference to `JobCreationFactory::createJobs(HardDisk)'
osTester.cxx:(.text+0xee): undefined reference to `HardDisk::setNumberOfJobs(int)'
osTester.cxx:(.text+0x2fe): undefined reference to `OS::setSchedulingAlgorithm(int)'
osTester.cxx:(.text+0x32c): undefined reference to `OS::osTakeOver(HardDisk, Ram, Cpu, Mouse, Monitor, Keyboard)'
collect2: ld returned 1 exit status
make[2]: *** [src/simulation] Error 1
make[1]: *** [src/CMakeFiles/simulation.dir/all] Error 2
make: *** [all] Error 2

how can i fix this error?

CODE follows :

#include <iostream>
#include <ostream>
#include <vector>
#include<string>
//#include <boost/shared_ptr.hpp>
#include "OS.hxx"
#include "Ram.hxx"
#include "Cpu.hxx"
#include "HardDisk.hxx"
#include "JobCreationFactory.hxx"
#include "Mouse.hxx"
#include "Monitor.hxx"
#include "Keyboard.hxx"

using namespace std;
typedef vector<int>LISTOFINT;
typedef LISTOFINT::iterator INT_ITER;

//namespace bo=boost;
//using bo::shared_ptr;
/* This is the main driver of the simulation,it makes all simulated devices available 
 and ready for use before operating system takes over(osTakeOver())
 */

int main(){

    int numberOfJobs = 0;
    bool simulate = false;
    string start;
    LISTOFINT schedulingAlgorithms; // 1 for SJF(Shortest Job first) and 2:for RR(Round Robbin)
    LISTOFINT numberOfResourcesAvailable;
    int mouseAvailable;
    int monitorAvailable;
    int keyboardAvailable;
    HardDisk HD;
    OS myOS;
    Cpu myCpu;
    Ram myRam;
    Mouse myMouse;
    Monitor myMonitor;
    Keyboard myKeyboard;
    JobCreationFactory j;

    j.createFiles(HD);
    j.createJobs(HD);

    //set defaut number of jobs to be used in the simulation .. allow user to input number of jobs
    cout << "***For simulation we use multiple instances of Mouse Monitor and Keyboard, this is actually the number of process a DeviceQ can handle at a g***\n";
    cout << "Enter number of Jobs to be used in the simulation (eg 40000) follwed by the number of available resources say ( 6 8 9) followed by 's' then hit Carriage return key>>>\n";
    while (cin >> numberOfJobs >> mouseAvailable >> monitorAvailable >> keyboardAvailable && !simulate) {
        simulate = true;
        HD.setNumberOfJobs(numberOfJobs);
    }   
    numberOfResourcesAvailable.push_back(mouseAvailable);
    numberOfResourcesAvailable.push_back(monitorAvailable);
    numberOfResourcesAvailable.push_back(keyboardAvailable);
    //setAvailable Resources
    //myOS.setAvailable(numberOfResourcesAvailable);

    INT_ITER aBegin = numberOfResourcesAvailable.begin();
    INT_ITER aEnd = numberOfResourcesAvailable.end();
    cout << "Initial number of resources Available (Mouse Monitor Keyboard):";
    for (; aBegin != aEnd; ++aBegin) {
        cout << *aBegin << " ";
    }
    cout << endl;
    /*simulate based on SJF then RR using the same number of resources then compare results
     *repeating the same algorithm a few more times would give a better comparison since this simulation
     *is entirely based on random number generation
    */
    schedulingAlgorithms.push_back(1);
    schedulingAlgorithms.push_back(2);
    INT_ITER sBegin = schedulingAlgorithms.begin();
    INT_ITER sEnd = schedulingAlgorithms.end();

    //at this point all devices are ready so an assumption can be made that 
    //BIOS has successfully checked devices hence BIOSdone = true
    //once everything is ready BIOS Loads OS
    cout << "SJF and RR are represented by:";
    for (; sBegin != sEnd; ++sBegin) {// for both algorithms
        cout << *sBegin <<" ";
        myOS.setSchedulingAlgorithm(*sBegin);
        myOS.osTakeOver(HD,myRam,myCpu,myMouse,myMonitor,myKeyboard);
    }
    cout << "respectively\n";
    cout << endl;
    //for now the smulation progress will be seen on the console

    return 0;

}
Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
user599319
  • 1
  • 1
  • 1

3 Answers3

3

The easiest way is to look if you have defined this symbol

undefined reference to `JobCreationFactory::createFiles(HardDisk)'

In the JobCreationFactory.cxx.o translation unit. Most likely you have declared it in JobCreationFactory.hxx but have not defined it in the corresponding implementation.


based on your other question that this one is a near exact duplicate of, I think I know what's going on. In JobCreationFactory.cxx you are not defining the class methods, you are redeclaring them

class JobCreationFactory{
    int numOfJobs;
    int numOfFiles;
    int time;
    int size;
    LISTOFINT header;

    JobCreationFactory()
    :numOfJobs(0),time(0),size(0)
    {
    }

Don't do that, do this instead

JobCreationFactory::JobCreationFactory() : numOfJobs(0),time(0),size(0)
{

}

and so on, for all the methods declared in JobCreationFactory.h. If this concept is confusing to you, you might want to get a good book about C++.

Community
  • 1
  • 1
Sam Miller
  • 23,808
  • 4
  • 67
  • 87
1

Linking errors are usually due to:

  • Forgetting to define the symbol/function. Some people simply forget to do the implementation on the .cpp file.

  • Defining the wrong symbol. It was supposed to be one thing but it was defined as another, very similar.

  • Not linking with the right library. If that function was not implemented by you, it means the symbol is defined somewhere else.

karlphillip
  • 92,053
  • 36
  • 243
  • 426
0

Try to use IDE like Visual Studio or Code::Block, etc. That tools may help you with these compile and link problem.

Jason
  • 3,237
  • 4
  • 26
  • 28