English 中文(简体)
C++ B. 连接错误
原标题:C++ Linking error
  • 时间:2011-03-30 03:04:36
  •  标签:
  • c++
  • linker

I have multiple classes connected by hxx header files and inheritance.This is all about OS simulation. I compiled them individually to see if i get any syntax errors but that was not the case.instead when i compile my main driver osTester.cxx i get linking error like this

#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.test();
    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 << "Enter number of Jobs to be used in the simulation (eg 40000) followed by space then   S  for Start:";
    while (cin >> numberOfJobs >> start && !simulate) {
        simulate = true;
        HD.setNumberOfJobs(numberOfJobs);
    }   
    cout << "Enter the number of processes that a mouseQ can handle:(say 6)";
    cin >> mouseAvailable;
    cout << "Enter the number of processes that a monitoQ can handle:(say 7)";
    cin >> monitorAvailable;
    cout << "Enter the number of processes that a keyboardQ can handle:(say 8)";
    cin >> keyboardAvailable;
    numberOfResourcesAvailable.push_back(mouseAvailable);
    numberOfResourcesAvailable.push_back(monitorAvailable);
    numberOfResourcesAvailable.push_back(keyboardAvailable);
    //setAvailable Resources
    myOS.setAvailable(numberOfResourcesAvailable);
    
    /*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
    
    for (; sBegin != sEnd; ++sBegin) {// for both algorithms
        myOS.setSchedulingAlgorithm(*sBegin);
        myOS.osTakeOver(HD,myRam,myCpu,myMouse,myMonitor,myKeyboard);
    }
    //for now the smulation progress will be seen on the console
    
    return 0;
    
}

I have tried using CMake but i still get the following error

Linking CXX executable osTester
Undefined symbols:

  "JobCreationFactory::createFiles(HardDisk)", referenced from:
      _main in osTester.cxx.o
  "OS::setAvailable(std::vector<int, std::allocator<int> >)", referenced from:
      _main in osTester.cxx.o
  "OS::osTakeOver(HardDisk, Ram, Cpu, Mouse, Monitor, Keyboard)", referenced from:
      _main in osTester.cxx.o
  "HardDisk::setNumberOfJobs(int)", referenced from:
      _main in osTester.cxx.o
  "OS::setSchedulingAlgorithm(int)", referenced from:
      _main in osTester.cxx.o
  "JobCreationFactory::createJobs(HardDisk)", referenced from:
      _main in osTester.cxx.old: symbol(s) not found

collect2: ld returned 1 exit status
make[2]: *** [src/osTester] Error 1
make[1]: *** [src/CMakeFiles/osTester.dir/all] Error 2
make: *** [all] Error 2

请帮助!


Update:

我有: cxx和原型中的文档。

I really don t understand the main problem. Please refer to the following Jobcreationfactory.cxx and .hxx respectively, and osTester.cxx (included in earlier post). I tried invoking a method from different class say OS and I get the same linking error.

#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include "random.hxx"
#include "Jobs.hxx"
#include "HardDisk.hxx"
#include "File.hxx"

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

class JobCreationFactory{
    int numOfJobs;
    int numOfFiles;
    int time;
    int size;
    LISTOFINT header;
    
    JobCreationFactory()
    :numOfJobs(0),time(0),size(0)
    {
    }
    
     int getNumberOfJobs() 
    {
        return numOfJobs;
    }
    
     void createFiles(HardDisk hd)
    {   string file = "File";
        string intval;
        stringstream ss (stringstream::in | stringstream::out);
        RandomSeq r1(10000, 20000);
        numOfFiles = r1();
        RandomSeq r2(10, 100);
        for(int j = 0; j<=numOfFiles; j++ )
        {
            ss << j+1;
            ss >> intval;
            file.append(intval);
            hd.storeFiles(File(file,r2()));
        }
    }
    
     void createJobs(HardDisk hd)
    {
        string job = "Job";
        string intval;
        stringstream ss (stringstream::in | stringstream::out);
        RandomSeq r1(60000,70000);
        numOfJobs = r1();
        int instructionException = (int)(0.1 * numOfJobs);
        
        for (int i = 1; i < getNumberOfJobs()+ 1; i++) 
        {
            RandomSeq r1(0, 2);
            RandomSeq r2(0, numOfFiles);
            size = assignSize(); 
            time = assignTime(size);
            setHeader();
            ss << i;
            ss >> intval;
            job.append(intval);
            Jobs newJob(job,size, time, header,r1());
            if(i%instructionException == 0)
            {
                newJob.setInstructionException(true);
            }
            for(int k = 0; k<newJob.getNumberOfFiles();k++)
            {
                newJob.associateJobWithFiles(k, r2());
            }
            hd.storeJobs(newJob);
        }
    }
    
     int assignSize()
    {
        RandomSeq r1(500,5000);
        int size = r1();
        return size;
    }
    
     int assignTime(int size)
    {
        int time =0;
        RandomSeq r1(10,20);
        RandomSeq r2(20,30);
        RandomSeq r3(30,40);
        RandomSeq r4(40,50);
        RandomSeq r5(50,60);
        RandomSeq r6(60,70);
        RandomSeq r7(70,80);
        RandomSeq r8(80,90);
        RandomSeq r9(90,100);
        
        if(size>=500&&size < 1000)
        {
            time = r1();
        }
        else if(size>=1000&&size < 1500)
        {
            time = r2();
        }
        else if(size>=1500&&size < 2000)
        {
            time = r3();
        }
        else if(size>=2000&&size < 2500)
        {
            time = r4();
        }
        else if(size>=2500&&size < 3000)
        {
            time = r5();
        }
        else if(size>=3000&&size < 3500)
        {
            time = r6();
        }
        else if(size>=3500&&size < 4000)
        {
            time = r7();
        }
        else if(size>=4000&&size < 4500)
        {
            time = r8();
        }
        else
        {
            time = r9();
        }
        
        return time;
        
    }
    
     string assignIO()
    {
        RandomSeq r1(1,5);
        int num = r1();
        string need="";
        
        if(num == 1)
        {
            need = "keyboard";
        }
        else if(num == 2)
        {
            need = "mouse";
        }
        else if(num == 3)
        {
            need = "Both"; // keyboard and mouse
        }
        else if(num == 4)
        {
            need ="file";
        }
        else
        {
            need = "nothing";
        }
        return need;
    }
    
    
     void setHeader()
    {
        RandomSeq r1(0,4);
        RandomSeq r2(0,3);
        RandomSeq r3(0,2);
        INT_ITER hIter = header.begin();
        header.insert(hIter,r1());
        header.insert(hIter+1,r2());
        header.insert(hIter+2,r3());
    }
    
     int getNumberOfFiles() {
        return numOfFiles ;
    }
    void test(){
        cout << "Testing JobCreationFactory
";
    }
        
};
int main(){
    return 0;
}

页: 1

#ifndef JobCreationFactory_hxx__
#define JobCreationFactory_hxx__
#include "HardDisk.hxx"
class JobCreationFactory {
public:
    //JobCreationFactory(){
    //}
    int getNumberOfJobs();
    void createFiles(HardDisk hd);
    void createJobs(HardDisk hd);
    int assignSize();
    int assignTime(int size);
    string assignIO();
    void setHeader();
    int getNumberOfFiles();
    void test();
};

#endif // JobCreationFactory_hxx_
问题回答

单独处理是对yn合物错误的合理检验,但在将 individually物单独联系起来方面没有任何意义。

因此,找到汇编者在没有链接的情况下汇编的备选办法(Microsoft View C++:/c, g++:-c)并加以使用。

这一错误告诉你,“职业技能”方法没有定义:createFiles——因此,你要么想确定,在任何地方的任何档案中,或界定该方法的档案都与“os”没有联系。 (是称呼的档案)。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签