初学C++builder 11,不知道为什么出现link32错误,找遍网上也不知道是什么原因

星空物宇 2023-09-13 02:07:49

具体错误信息为[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也没有有用的解释,只告诉我

  1. Form2.cpp 没有包含 Unit1.h:请确保 Form2.cpp 文件的开头包含了 #include "Unit1.h"。这是确保 Form2 类的声明与其实现一致的关键。

  2. Unit1.cpp 和 Form2.cpp 不在同一个项目中:如果 Unit1.cppForm2.cpp 不在同一个项目中,链接器就无法找到 _Form2 对象。请确保它们都包含在同一个项目中,并且项目文件正确配置。

  3. Unit1.cpp 中的代码存在问题:确保 Unit1.cpp 中的代码没有语法错误或逻辑错误,这可能导致链接错误。

  4. 不正确的命名约定:请检查 Unit1.cppForm2.cpp 中的类名和函数名,确保它们的大小写和拼写都正确。C++ 是区分大小写的语言

但我这些都没啥问题啊 在一个项目也包含了,代码应该也没有问题,真的想不出来问题了

 

 

...全文
354 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
moneytree 2023-11-30
  • 打赏
  • 举报
回复
加上include就行了。
wh1965 2023-11-06
  • 打赏
  • 举报
回复 1

C++Builder 就是这个样子,不稳定。我在 C++Builder XE11.3 安装 ZeosDBO 7.2/8.0 安装过程各种坑! 最后7.2 算是安装上了,可是,把zeosConnection 加 到窗体 编译后,无法连接为 exe

ooolinux 2023-11-06
  • 举报
回复
@wh1965 三方控件设置一下library目录,可以全局也可以工程选项
星空物宇 2023-09-14
  • 打赏
  • 举报
回复

img

ooolinux 2023-09-13
  • 打赏
  • 举报
回复

TForm2 Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent
Owner)
: TForm(Owner)
{
}
这些被你删除了。如果你要做命令行程序,用dev-cpp更方便。

ooolinux 2023-09-13
  • 举报
回复
@ooolinux 看了一下有界面控件,但没看清你的函数是从哪里被调用的,比如按钮点击或者定时器启动?
星空物宇 2023-09-14
  • 举报
回复
@ooolinux 使用定时器 Timer1 来模拟时间片轮转,定时触发 running 函数运行就绪队列的头进程。
星空物宇 2023-09-14
  • 举报
回复
@ooolinux 但是这个和这个报错有什么关系吗搞不明白为啥一直无法识别
5条回复
星空物宇 2023-09-13
  • 打赏
  • 举报
回复
//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";
}
//----------------------------------------------------------------------


ooolinux 2023-09-13
  • 打赏
  • 举报
回复 1

贴project.cpp和unit2.cpp看看

星空物宇 2023-09-13
  • 举报
回复
@ooolinux 已经贴好了,麻烦大佬看看
【为什么还需要学习C++?】 你是否接触很多语言,但从来没有了解过编程语言的本质?你是否想成为一名资深开发人员,想开发别人做不了的高性能程序?你是否经常想要窥探大型企业级开发工程的思路,但苦于没有基础只能望洋兴叹? 那么C++就是你个人能力提升,职业之路进阶的不二之选。【课程特色】 1.课程共19大章节,239课时内容,涵盖数据结构、函数、类、指针、标准库全部知识体系。2.带你从知识与思想的层面从0构建C++知识框架,分析大型项目实践思路,为你打下坚实的基础。3.李宁老师结合4大国外顶级C++著作的精华为大家推出的《征服C++11》课程。【学完后我将达到什么水平?】 1.对C++的各个知识能够熟练配置、开发、部署;2.吊打一切关于C++的笔试面试题;3.面向物联网的“嵌入式”和面向大型化的“分布式”开发,掌握职业钥匙,把握行业先机。【面向人群】 1.希望一站式快速入门的C++初学者; 2.希望快速学习 C++、掌握编程要义、修炼内功的开发者; 3.有志于挑战更高级的开发项目,成为资深开发的工程师。 【课程设计】 本课程包含3大模块基础篇本篇主要讲解c++的基础概念,包含数据类型、运算符等基本语法,数组、指针、字符串等基本词法,循环、函数、类等基本句法等。进阶篇本篇主要讲解编程中常用的一些技能,包含类的高级技术、类的继承、编译链接和命名空间等。提升篇:本篇可以帮助学员更加高效的进行c++开发,其中包含类型转换、文件操作、异常处理、代码重用等内容。

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧