13,825
社区成员
具体错误信息为[ilink32 Error] Error: Unresolved external '_Form2' referenced from C:\USERS\青衫客WHY\DOCUMENTS\EMBARCADERO\STUDIO\PROJECTS\WIN32\DEBUG\PROJECT1.OBJ
[ilink32 Error] Error: Unresolved external 'TForm2::' referenced from C:\USERS\青衫客WHY\DOCUMENTS\EMBARCADERO\STUDIO\PROJECTS\WIN32\DEBUG\PROJECT1.OBJ
[ilink32 Error] Error: Unable to perform link
真的不是很明白,问了gpt也没有有用的解释,只告诉我
Form2.cpp 没有包含 Unit1.h:请确保 Form2.cpp
文件的开头包含了 #include "Unit1.h"
。这是确保 Form2
类的声明与其实现一致的关键。
Unit1.cpp 和 Form2.cpp 不在同一个项目中:如果 Unit1.cpp
和 Form2.cpp
不在同一个项目中,链接器就无法找到 _Form2
对象。请确保它们都包含在同一个项目中,并且项目文件正确配置。
Unit1.cpp 中的代码存在问题:确保 Unit1.cpp
中的代码没有语法错误或逻辑错误,这可能导致链接错误。
不正确的命名约定:请检查 Unit1.cpp
和 Form2.cpp
中的类名和函数名,确保它们的大小写和拼写都正确。C++ 是区分大小写的语言
但我这些都没啥问题啊 在一个项目也包含了,代码应该也没有问题,真的想不出来问题了
C++Builder 就是这个样子,不稳定。我在 C++Builder XE11.3 安装 ZeosDBO 7.2/8.0 安装过程各种坑! 最后7.2 算是安装上了,可是,把zeosConnection 加 到窗体 编译后,无法连接为 exe
TForm2 Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent Owner)
: TForm(Owner)
{
}
这些被你删除了。如果你要做命令行程序,用dev-cpp更方便。
//priject.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", Form2);
//---------------------------------------------------------------------------
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
try
{
Application->Initialize();
Application->MainFormOnTaskBar = true;
Application->CreateForm(__classid(TForm2), &Form2);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
//unit1.cpp
#include <vcl.h> // 这是 VCL (Visual Component Library) 头文件,它包含了许多与界面和窗体相关的定义。
#include <tchar.h> // 这是 TCHAR 类型的头文件,用于跨平台的字符处理。
#include<cstdlib>
#include"Unit1.h"
struct pcb{
int id; //进程序号
int ra; //所需资源A的数量
int rb; //所需资源B的数量
int rc; //所需资源C的数量
int ntime; //所需的时间片个数
int rtime; //已经运行的时间片个数
char state; //进程状态
struct pcb *next;
} *hready=NULL,*hblock=NULL,*p; //hready,hblock分别为指向就绪和阻塞队列
typedef struct pcb PCB;
int m,n,r,a,b,c,h=0,i=1,time1Inteval; //m为要模拟的进程个数,n为初始化进程个数,a,b,c分别为A,B,C
//三类资源的总量 ,h为时间片运行的次数
//------------------------------------------------------------------------------
//建立一个PCB结构体型的空链表
PCB *increat(void)
{ PCB *head;
head=NULL;
return(head);
}
//------------------------------------------------------------------------------
//从链表起始地址开始输出该链表的内容
PCB* getpcb() {
PCB* pcb = new PCB;
// 这里可以根据你的需求初始化 PCB 结构体的各个成员
pcb->id = 0; // 初始化为0,你可以根据需要设置不同的值
pcb->ra = 0;
pcb->rb = 0;
pcb->rc = 0;
pcb->ntime = 0;
pcb->rtime = 0;
pcb->state = 'W'; // 初始化为'W',你可以根据需要设置不同的状态
pcb->next = NULL; // 初始化下一个指针为NULL
return pcb;
}
void disp(PCB *head)
{PCB *p1;
p1=head;
AnsiString str2;
if(head!=NULL) //链表非空
{
do
{
str2+=" ";
str2+=IntToStr(p1->id);str2+=" ";
str2+=(p1->state);str2+=" ";
str2+=IntToStr(p1->ra);str2+=" ";
str2+=IntToStr(p1->rb);str2+=" ";
str2+=IntToStr(p1->rc);str2+=" ";
str2+=IntToStr(p1->ntime);str2+=" ";
str2+=IntToStr(p1->rtime);str2+="\r\n";
p1=p1->next;
}while(p1!=NULL); //不断输出进程的信息,直到链尾!
} //if
else
{ str2+="\t\t该 队 列 中 没 有 进 程!\r\n" ;}
Form2->Memo1->Lines->Add(str2);
}//disp
//------------------------------------------------------------------------------
/*将进程插入到链尾*/
PCB *insert(PCB *head,PCB*pcb) //带两个指针形参
{PCB *pi,*p1;
p1=head;
pi=pcb;
if(head==NULL)
{head=pi;pi->next=NULL;}
else
{while(p1->next!=NULL)
{p1=p1->next;
}
p1->next=pi;
pi->next=NULL;}
return(head);
}
void input() //对进程进行初始化
{
AnsiString str1;
m=StrToInt (Form2->Edit1->Text); //读取填入的进程总数
n=StrToInt (Form2->Edit2->Text); //读取需初始化进程数
a=StrToInt (Form2->Edit3->Text); //读取A类资源的总数
b=StrToInt (Form2->Edit4->Text); //读取B类资源的总数
c=StrToInt (Form2->Edit5->Text); //读取C类资源的总数
time1Inteval=StrToInt(Form2->Edit6->Text);
Form2->Timer1->Interval=time1Inteval;
r=m-n;
for(i=1;i<=n;i++) //初始化进程信息,直到到达要初始化个数
{
p=getpcb();
p->id=i;
str1+=" 产生进程ID:";str1+=IntToStr(p->id);str1+="\r\n";
p->ra=(random(a-3)+3);
str1+=" 所需A类资源数:";str1+=IntToStr(p->ra);str1+="\r\n";
p->rb=(random(b));
str1+=" 所需B类资源数:";str1+=IntToStr(p->ra);str1+="\r\n";
p->rc=(random(c-2)+2);
str1+=" 所需C类资源数:";str1+=IntToStr(p->ra);str1+="\r\n";
p->ntime=(random(5)+1);
str1+=" 所需时间片个数:";str1+=IntToStr(p->ntime);str1+="\r\n";
p->rtime=0;
p->next=NULL;
if (((a-(p->ra))>=0)&&((b-(p->rb))>=0)&&((c-(p->rc))>=0)) //如果资源符合所需要求
{ //则写入就绪队列队尾
a=a-(p->ra); //当前所剩A类资源数目
b=b-(p->rb); //当前所剩B类资源数目
c=c-(p->rc); //当前所剩C类资源数目
p->state='W';
hready=insert(hready,p); //将进程插入就绪队列
}//if
else
{
p->state='B';
hblock=insert(hblock,p);
}
str1+=" 当前进程状态:";
str1+=(p->state);
str1+="\r\n";
str1+="\r\n";
}//for
Form2->Memo1->Lines->Add(str1);
}//input
//------------------------------------------------------------------------------
void check() //输出就绪队列和阻塞队列的信息
{AnsiString str1,str2,str3;
str3+="\r\n" ;
str3+="= = = = = = = = = = = = = = = CPU时间片运行了: " ;
str3+=IntToStr(h);
str3+=" 次= = = = = = = = = = = = = = =\r\n";
Form2->Memo1->Lines->Add(str3);
str1+="*********************************当 前 就 绪 队 列 的 信 息" ;
str1+="*********************************\r\n" ;
str1+="进程ID 进程状态 A资源数 B资源数 C资源数 需要时间片 已运行时间片";
Form2->Memo1->Lines->Add(str1);
disp(hready);
str2+="*********************************当 前 阻 塞 队 列 的 信 息";
str2+="*********************************\r\n" ;
str2+="\r\n";
str2+="进程ID 进程状态 A资源数 B资源数 C资源数 需要时间片 已运行时间片";
Form2->Memo1->Lines->Add(str2);
disp(hblock);
}//check
//---------------------------------------------------------------------------
PCB *running(PCB *head) //运行就绪队列的头进程
{
PCB *p1;
p1=head;
AnsiString str4;
if(p1->next==NULL)
head=increat();
else
{head=p1->next;
}
p1->state='R'; //进程状态由就绪转向运行
(p1->rtime)++;
h++;
str4+="~~~~~~~~~~~~~~~~ 当前正在运行的进程ID是: ";
str4+=IntToStr(p1->id);
str4+=" ~~~~~~~~~~~~~~~~~~\r\n";
str4+="进程ID 进程状态 A资源数 B资源数 C资源数 需要时间片 已运行时间片\r\n";
str4+=" ";
str4+=IntToStr(p1->id);str4+=" ";
str4+=(p1->state);str4+=" ";
str4+=IntToStr(p1->ra);str4+=" ";
str4+=IntToStr(p1->rb);str4+=" ";
str4+=IntToStr(p1->rc);str4+=" ";
str4+=IntToStr(p1->ntime);str4+=" ";
str4+=IntToStr(p1->rtime);str4+=" ";
Form2->Memo1->Lines->Add(str4);
if(p1->ntime==p1->rtime) //如果已经运行的时间片到达所需次数
{
str4+="\r\n\r\n\t\tID号为:";
str4+=IntToStr(p1->id);
str4+=" 的进程已经完成!!!";
Form2->Memo1->Lines->Add(str4);
a=a+(p1->ra);
b=b+(p1->rb);
c=c+(p1->rc);
free(p1); //释放当前指针
}
else
{
p1->state='W';
head=insert(head,p1);
}
return(head);
}//running
//---------------------------------------------------------------------------
void testblock() //检测当前资源数目是否满足阻塞队列里进程的需求
{PCB *p1,*p2;
p1=hblock;
p2=hblock;
AnsiString str5;
while((hblock!=NULL)&&(p1!=NULL))
{
if((a-(p1->ra)>=0)&&(b-(p1->rb)>=0)&& (c-(p1->rc)>=0)) //如果满足
{if(p1==hblock)
{
hblock=p1->next;
p1->state='W';
hready=insert(hready,p1); //将阻塞的进程插入就绪队列
a=a-(p->ra);
b=b-(p->rb);
c=c-(p->rc);
str5="\tID号为: " ;
str5+=IntToStr(p1->id);
str5+=" 的进程由阻塞队列转入就绪队列!\r\n";
p1=hblock;
} //if(p1==hblock)
else
{p2->next=p1->next;
p1->state='W';
hready=insert(hready,p1);
str5="\tID号为: " ;
str5+=IntToStr(p1->id);
str5+=" 的进程由阻塞队列转入就绪队列!\r\n";
p1=p2->next;
}//else
} //大if
else
{p2=p1;
p1=p1->next;
} //else
Form2->Memo1->Lines->Add(str5);
} //whlie
}//block
//---------------------------------------------------------------------------
void testnew() //检测是否有新的进程产生
{
int t;
AnsiString str6;
if(r>0)
{
t=random(9); //生成随机数
if(t<=7) //如果随机数小于等于7,则产生新进程,否则不产生
{
p=getpcb();
str6+="有新的进程申请加入:\r\n" ;
p->id=i++;
str6+="进程ID:";
str6+=IntToStr(p->id);
str6+="\r\n";
p->ra=(random(a-3));
str6+="所需A类资源数:";
str6+=IntToStr(p->ra);
str6+="\r\n";
p->rb=(random(b-3));
str6+="所需B类资源数:";
str6+=IntToStr(p->ra);
str6+="\r\n";
p->rc=(random(c-3));
str6+="所需C类资源数:";
str6+=IntToStr(p->ra);
str6+="\r\n";
p->ntime=(random(5)+1);
str6+="所需时间片个数:";
str6+=IntToStr(p->ntime);
str6+="\r\n";
p->rtime=0;
p->next=NULL;
if (((a-(p->ra))>=0)&&((b-(p->rb))>=0)&&((c-(p->rc))>=0))
{ //进程满足要求,进入阻塞队列
a=a-(p->ra);
b=b-(p->rb);
c=c-(p->rc);
p->state='w';
str6+="当前进程状态:";
str6+=(p->state);
str6+="\r\n";
hready=insert(hready,p);
str6+="资源满足新进程需求,该进程进入就绪队列!";
}//if
else //进程不满足要求,进入阻塞队列
{
p->state='B';
hblock=insert(hblock,p);
str6+="当前进程状态:";
str6+=(p->state);
str6+="\r\n";
str6+="资源不能满足新进程需求,该进程进入阻塞队列!" ;
}//else
}//for
Form2->Memo1->Lines->Add(str6);
}//if(r>0)
r--;
}//testnew
//---------------------------------------------------------------------------
void runmain() //运行的主函数
{
AnsiString str,str1;
input();
Form2->Timer1->Enabled=true;
str+="\r\n";
}
//----------------------------------------------------------------------