2011-04-26 75 views
0

我寫了下面的代碼實現循環賽代碼,但在VS2010工作正常

* // roundrobin.cpp:

#include <iostream> 

using namespace std; 

int main() 
{ 

    int numpros; 

    int temp=0; 

    cout<<"enter # of processes="; 

    cin>>numpros; 


    int twt=0; 

    int* wt=new int[numpros]; 

    int* bt=new int[numpros]; 

    int* eqs=new int[numpros]; 

    int* remainder=new int[numpros]; 

    int max=0; 

    int tbt=0; 

    int nfq=0; 

    int n,o,p,q,r; 

    cout<<"enter burst time of each proccess"<<endl; 

    for(q=0;q<numpros;q++) 

     wt[q]=0; 

    for(int i=0;i<numpros;i++) 

    { 


     cout<<"burst time "<<i<<"="; 

     cin>>bt[i]; 

     //tbt=bt[i]+tbt;  

     } 

    for(int j=0;j<numpros;j++) 

    { 

     cout<<"# of quantums of process "<<j<<"="; 

     eqs[j]=bt[j]/4; 

     remainder[j]=bt[j]%4; 

     if(eqs[j]>max) 

     { 

      max=eqs[j]; 
      temp=j; 
     } 

     cout<<eqs[j]<<" "<<remainder[j]<<endl; 

    } 

    if(remainder[temp]>0)max++; 

    //cout<<max<<endl; 

    int tslicetime=numpros*4; 

    for(int m=0;m<max;m++) 

    { 

     for(n=0;n<numpros;n++) 

     { 
      if(bt[n]>4) 

      { 
       bt[n]=bt[n]-4; 
       for(o=0;o<numpros;o++) 
       { 
        if(o!=n && bt[o]>0) 
        { 
         wt[o]+=4; 
        } 

       } 
      } 
      else if(bt[n]<=4) 
      { 

        for(p=0;p<numpros;p++) 
       { 
        if(p!=n && bt[p]>0) 
        { 
         wt[p]+=bt[n]; 
        } 

       } 
        bt[n]=0; 
      } 

      cout<<"p"<<n<<"="<<bt[n]<<" "; 
     } 


    } 
    cout<<endl; 
    for(r=0;r<numpros;r++){ 


    } 
    cout<<endl; 
     for(r=0;r<numpros;r++){ 

     cout<<"waiting time "<<r<<"="<<wt[r]<<endl; 
    } 

} 

它是在VS2010工作正常,但GCC是給下面的錯誤在編譯

[email protected]:~/codes$ g++ rr rr.cpp 
rr: In function `_start': 
(.text+0x0): multiple definition of `_start' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.text+0x0): first defined here 
rr:(.rodata+0x0): multiple definition of `_fp_hw' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata+0x0): first defined here 
rr: In function `_fini': 
(.fini+0x0): multiple definition of `_fini' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.fini+0x0): first defined here 
rr:(.rodata+0x4): multiple definition of `_IO_stdin_used' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here 
rr: In function `__data_start': 
(.data+0x0): multiple definition of `__data_start' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.data+0x0): first defined here 
rr: In function `__data_start': 
(.data+0x4): multiple definition of `__dso_handle' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o:(.data+0x0): first defined here 
rr: In function `_init': 
(.init+0x0): multiple definition of `_init' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.init+0x0): first defined here 
/tmp/ccB1Drkq.o: In function `main': 
rr.cpp:(.text+0x0): multiple definition of `main' 
rr:(.text+0xb4): first defined here 
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__' 
rr:(.dtors+0x4): first defined here 
/usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored. 
/usr/bin/ld: error in rr(.eh_frame); no .eh_frame_hdr table will be created. 
collect2: ld returned 1 exit status 
+3

你應該運行「g ++ -o rr rr.cpp」嗎?目前,您的命令行似乎試圖將二進制輸出作爲源文件之一。 – forsvarir 2011-04-26 13:43:18

+1

......當然,你正在編譯的文件是'rr.cpp',而不是'roundrobin.cpp',但我確定這是故意/錯字? – forsvarir 2011-04-26 13:54:57

回答

0

你有g++ rr rr.cpp BU你想要g++ -o rr rr.cpp。您試圖將可執行文件鏈接到自身,導致重複的符號。

相關問題