當我嘗試編譯它們時,我有多個C++類文件和頭文件我得到以下錯誤。我甚至嘗試使用cmake使我的生活更輕鬆,但我仍然得到它:什麼是最簡單的方法來解決C++鏈接錯誤
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
我該如何解決這個錯誤?
代碼如下:
#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;
}
@user請格式化您的問題中的代碼。 – 2011-03-31 00:01:03
[可能的重複](http://stackoverflow.com/q/5481409/283302)。 – 2011-03-31 00:44:15