代码在 gcc 上不起作用,但在 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 在编译时给出以下错误
moni@moni-laptop:~/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
i wrote the following code for implementing round robin
*// 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;
}
}
it is working fine on vs2010 but gcc is giving following error on compilation
moni@moni-laptop:~/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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有
g++ rr rr.cpp
,但您需要g++ -o rr rr.cpp
。您试图将可执行文件链接到其自身,从而导致重复的符号。You have
g++ rr rr.cpp
but you wantg++ -o rr rr.cpp
. You're trying to link the executable to itself, resulting in duplicate symbols.