Thread: Need help quick, compiler/file problem.

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    7

    Need help quick, compiler/file problem.

    Hey guys,
    I just finished coding my first program in c++ and now I am getting this error when I try to run the executable file:


    ld.so.1: printqexe: fatal: libstdc++.so.5: open failed: No such file or directory


    I don't know much about c++ so I have no clue what this means. I have to turn this assignment in in 3 hours so time is sort of critical.

    Thanks in advance,

    Alex

  2. #2
    Registered User
    Join Date
    Apr 2005
    Posts
    7
    Heres a little background info.

    Compiler: GNU g++ (not sure what version)
    OS: Unix
    I am on using a telnet client to access my school's unix server.

  3. #3
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Sounds more like OS trouble than code trouble.
    There are diff versions of "libstdc++.so.X" where X is a diff number.

    You say you are not sure what version of the compiler you are using, so I would guess you would not know how to make a symbolic link to the appropriate version you have?

    If it is not any Unix specific code try compiling it on a Windows or Linux box and see what happens.
    If it is not too big of a code, and it is ok to post it, do so. Maybe I am completely wrong with what I think the trouble is.

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    7
    Here is the code:
    First file:
    File: naivepq.cpp

    Code:
    #include <string>
    #include <iostream>
    #include <iomanip>
    #include "naivepq.h"
    
    using namespace std;
    
    /* private functions. */
    
    /**
       Function: assignjobid
       Usage: id = assignjobid(printq,numjobs);
       This function assigns a unique job id
       to a new print job.
       @param printq an array representing the printer queue.
       @param numjobs the current number of jobs in the queue.
       @return a number in the range 1..100 that has not been
               assigned to a job already in the queue.
     */
    static int assignjobid(job printq[],int numjobs)
    {
       int i, j, found;
       if (numjobs == 0)
          return 1;
       if (numjobs == MAX_JOBS)
          return 0;
       i = 0;
       while (i <= numjobs)
       {
          i++;
          j=0;
          found = 0;
          while(j<numjobs && !found)
          {
             if (printq[j].id == i)
                found = 1;
             j++;
          }
          if (!found)
             return i;
       }
       return numjobs+1;
    }
    
    }
    
    /* Define these functions. See descriptions in the header
       file.*/
    
    int addjob(job printq[], int& numjobs)
    {
       int i;
    
       job temp;
    
       if (numjobs==MAX_JOBS)
       return 0;
    
       if (numjobs<MAX_JOBS)
       {
        assignjobid(printq, numjobs);
    
        for(i=numjobs-1; i>0; i--)
            printq[i+1]=printq[i];
    
        cout<<"Enter the type of document, followed by the number of pages,";
        cout<<"followed by the job owner:";
    
        cin>>printq[0].id>>printq[0].pages>>printq[0].who;
    
        jobtype j;
    
        printq[0].kind=j;
    
     switch(j)
          {
            case TEXT: printq[0].duration=3;
            cin>>printq[0].duration;
            break;
    
            case IMAGE: printq[0].duration=6;
            cin>>printq[0].duration;
            break;
    
            case HTML: printq[0].duration=3;
            cin>>printq[0].duration;
            break;
    
            case POSTSCRIPT: printq[0].duration=4;
            cin>>printq[0].duration;
            break;
    
            case OTHERS: printq[0].duration=7;
            cin>>printq[0].duration;
            break;
    
            default: cerr<<"Invalid Type"<<endl;
    
          }
    
       return 1;
       }
    
    }
    
    int canceljob(job printq[], int& numjobs, int jobid)
    {
    int i, j, k;
    j=0;
    for(i=0; i<=numjobs; i++)
       {
       if (printq[i].id==jobid)
          {
            for(k=i; k<numjobs; k++)
            printq[k]=printq[k+1];
    
            numjobs--;
    
            j=1;
    
            return 1;
          }
       }
    return 0;
    }
    
    
    int servicejob(job printq[], int& numjobs)
    {
       if(numjobs==0)
       return 0;
    
       if(numjobs>0)
       {
        numjobs--;
    
        return 1;
       }
    }
    
    
    void printjoblist(job printq[], int numjobs)
    {
    int i;
    if (numjobs==0)
    cout<<"No Jobs In Queue"<<endl;
    else
       {
        for(i=numjobs; i>0; i--)
          {
            cout<<printq[i].id<<" -- "<<printq[i].who<<" -- ";
            cout<<printq[i].duration<<" -- ";
            jobtype j;
            j=printq[i].kind;
            switch (j)
              {
               case TEXT: cout<<"text"<<endl;
                    break;
               case IMAGE: cout<<"image"<<endl;
                    break;
               case HTML: cout<<"html"<<endl;
                    break;
               case POSTSCRIPT: cout<<"postscript"<<endl;
                    break;
               case OTHERS: cout<<"others"<<endl;
                    break;
               default: cout<<"invalid type"<<endl;
              }
          }
       }
    }

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    7
    Here is the second file:
    printq.cpp
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <fstream>
    
    #include "naivepq.h"
    
    int menu(void);
    
    using namespace std;
    
    int main(int argc, char **argv)
    {
       fstream fpjobs;
       job printq[MAX_JOBS];
       int numjobs, menuretval, id;
       numjobs = 0;
    
    /* Your tasks:
       ->Open jobs.dbf binary files
       ->initialize numjobs
       ->store the contents of jobs.dbf into printq[]
    */
            fpjobs.open ("jobs.dbf", ios::out | ios::binary);
            if (!fpjobs)
            {
               cerr<<"Error opening jobs.dbf"<<endl;
               exit(1);
            }
            int i, j;
            job jobtemp;
            for(i=0;i<MAX_JOBS; i++)
            {
              fpjobs.read((char*)(&jobtemp), sizeof(job));
              printq[i].id=jobtemp.id;
              printq[i].kind=jobtemp.kind;
              printq[i].duration=jobtemp.duration;
              printq[i].pages=jobtemp.pages;
              strcpy(printq[i].who, jobtemp.who);
            }
             fpjobs.close();
            i=0;
            j=1;
            while (j!=0)
            {
     {
              j=printq[i].id;
              i++;
            }
    
       while((menuretval=menu()))
       {
    
          switch (menuretval)
          {
             case 1: addjob(printq, numjobs);
                break;
             case 2: cout<<"Enter the id of the job: ";
                     cin>>id;
                     canceljob(printq, numjobs,id);
                break;
             case 3: servicejob(printq, numjobs);
                break;
             case 4: printjoblist(printq, numjobs);
                break;
             default: ;
          }
       }
    
       /* Your task:
          ->overwrite jobs.dbf with the contents of the
            printq[] array.
          ->close file
       */
            fpjobs.open("jobs.dbf", ios::trunc | ios::in | ios::binary);
            if (!fpjobs)
            {
              cerr<<"Error opening jobs.dbf"<<endl;
              exit(1);
            }
    
            for (i=0; i<numjobs; i++)
            {
             jobtemp.id=printq[i].id;
             jobtemp.kind=printq[i].kind;
             jobtemp.duration=printq[i].duration;
             jobtemp.pages=printq[i].pages;
             strcpy(jobtemp.who,printq[i].who);
             fpjobs.write((char*)&jobtemp, sizeof(job));
            }
             fpjobs.close();
       return 0;
    }
    
    int menu()
    {
       int c;
       char dummy;
       while (1)
       {
          cout<<"         P R I N T   Q U E U E       "<<endl;
          cout<<"====================================="<<endl;
          cout<<"Add job to queue..................[1]"<<endl<<endl;
          cout<<"Cancel job........................[2]"<<endl<<endl;
          cout<<"Service print job.................[3]"<<endl<<endl;
          cout<<"Print job listings................[4]"<<endl<<endl;
          cout<<"Quit..............................[0]"<<endl<<endl;
          cout<<"Select an option: ";
          cin>>c;
          cin.ignore(80,'\n');
          if (c < 0 || c > 4)
          {
             cerr<<"Invalid option. Press the [RETURN] key to continue.";
             cin>>dummy;
          }
          else
             return c;
       }
    }
    Last edited by alex0486; 09-27-2005 at 09:32 PM.

  6. #6
    Registered User
    Join Date
    Apr 2005
    Posts
    7
    Here is the third file:
    naivepq.h
    Code:
    const int MAX_JOBS = 100;
    
    /* User-defined type definitions */
    typedef char string80[81];
    
    /* define jobtype enumerated type and job struct below. */
    
    typedef enum _jobtype {TEXT, IMAGE, HTML, POSTSCRIPT, OTHERS} jobtype;
    
    typedef struct _job
    {
       int id;
       jobtype kind;
       long int duration;
       int pages;
       string80 who;
    }job;
    
    
    /* public functions: Implementation for these functions are in
       naivepq.c */
    
    /**
       Function: addjob
       Usage: retval = addjob(printq,numjobs);
       This function assigns adds a new job to the printq. If there
       are already MAX_JOBS in the print queue, the retval is set
       to 0 indicating failure: the queue is full and a new job
       cannot be added and numjobs remains unchanged.
       If the queue is not full, the function calls assignjobid
       to obtain a unique id for the new job. The user is then prompted
       for other details about the job:
       kind -> TEXT, IMAGE, HTML, POSTSCRIPT or OTHERS
       pages -> number of pages
       who -> job owner
       duration -> calculated as follows: TEXT 3 seconds/page, IMAGE 6
                   seconds/page, HTML 3 seconds/page, POSTSCRIPT 4
                   seconds/page, OTHERS 7 seconds/page
       The numjobs reference parameter is incremented by 1 and all other
       jobs are shifted one position to the right. The new job is placed
       at the back of the queue (index 0). The function returns 1.
       @param printq the array that represents the printer queue
       @param numjobs the current number of jobs in the queue
       @return returns 1 on success or 0 on failure.
     */
    int addjob(job printq[], int& numjobs);
    
    /**
       Function: canceljob
       Usage: retval = canceljob(printq,numjobs, jobid);
       This function cancels a job that has been submitted
       to the print queue. The function checks to determine
       whether the job id exists. If the job id is invalid, the
       function returns 0. Otherwise, it deletes the job from
       the queue by shifting every job succeeding the job one
       position back, reduces the reference parameter numjobs
       by 1 and returns 1 indicating success.
       @param printq the array that represents the printer queue
       @param numjobs the current number of jobs in the queue
       @param jobid a unique integer between 1 and 0 representng
              the job identification number.
       @return returns 1 on success or 0 on failure.
     */
    int canceljob(job printq[], int& numjobs, int jobid);
    
    /**
       Function: servicejob
       Usage: retval = servicejob(printq,numjobs);
       This function removes the job at the front of
       the print queue. If the queue is empty, the
       the function returns 0 indicating failure.
       Otherwise, it deletes the job from the queue by
       reducing the reference parameter numjobs
       by 1 and returns 1 indicating success.
       @param printq the array that represents the printer queue
       @param numjobs a reference parameter representing the
              current number of jobs in the queue
       @return returns 1 on success or 0 on failure.
     */
    int servicejob(job printq[], int& numjobs);
    
    /**
       Function: printjoblist
       Usage: printjoblist(printq,numjobs);
       This function prints a listing of all jobs
       currently on the queue, one job per line
       using the following format:
       id -- who -- pages -- duration -- kind (in words)
       If the queue is empty, the function prints a
       message indicating that there aren't any jobs on
       the queue.
       @param printq the array that represents the printer queue
       @param numjobs the current number of jobs in the queue
       @return none.
     */
    void printjoblist(job printq[], int numjobs);

  7. #7
    Registered User
    Join Date
    Apr 2005
    Posts
    7
    And that is all of them.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Compiler: GNU g++ (not sure what version)
    Try g++ -v

    OS: Unix
    Try uname -a

    Before trying a real program, how about starting with
    Code:
    #include <iostream>
    using namespace std;
    int main ( ) {
      cout << "hello world" << endl;
    }
    To make sure your compiler is at least installed correctly in it's most basic form.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. just a quick problem
    By Domdom in forum C++ Programming
    Replies: 9
    Last Post: 01-26-2006, 11:11 AM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM