Linker error (C++)

zingbats

Member
Joined
Aug 11, 2003
Messages
8
I have just purchased Borland C++ builder (I know :( I feel ashamed). I know these are about the .NET framework, but I wondered if you could help?!

I am following the tutorial but I am getting a linking error while compiling.

Here is my code (all of it) and the error:

The error is:
[Linker Error] Unresolved external __fastcall TForm1::HelpIndexExecute(System::TObject *) referenced from C:\BORLAND\PROJECTS\TEXTEDITOR\UNIT1.OBJ


Code:
//THE CPP FILE:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}

void __fastcall TForm1::FileNewExecute(TObject *Sender)
{
RichEdit1->Clear();
FileName = "untitled.txt";
StatusBar1->Panels->Items[0]->Text = FileName;        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FileOpen1Accept(TObject *Sender)
{
RichEdit1->Lines->LoadFromFile (FileOpen1->Dialog->FileName);

FileName = FileOpen1->Dialog->FileName;
StatusBar1->Panels->Items[0]->Text = FileName;        
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FileSaveExecute(TObject *Sender)
{
if (FileName == "untitled.txt") 

 FileSaveAs1->Execute();
else
	 RichEdit1->Lines->SaveToFile(FileName);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FileSaveAs1BeforeExecute(TObject *Sender)
{
FileSaveAs1->Dialog->InitialDir = ExtractFilePath (FileName);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FileSaveAs1Accept(TObject *Sender)
{
FileName = FileSaveAs1->Dialog->FileName;

RichEdit1->Lines->SaveToFile(FileName);
StatusBar1->Panels->Items[0]->Text = FileName;        
}
//---------------------------------------------------------------------------

And the .h file:
Code:
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ActnList.hpp>
#include <ActnMan.hpp>
#include <ComCtrls.hpp>
#include <StdActns.hpp>
#include <ActnCtrls.hpp>
#include <ActnMenus.hpp>
#include <ToolWin.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
        TRichEdit *RichEdit1;
        TStatusBar *StatusBar1;
        TActionManager *ActionManager1;
        TAction *FileNew;
        TAction *HelpAbout;
        TEditCut *EditCut1;
        TEditCopy *EditCopy1;
        TEditPaste *EditPaste1;
        TFileOpen *FileOpen1;
        TFileSaveAs *FileSaveAs1;
        TFileExit *FileExit1;
        TAction *FileSave;
        TActionMainMenuBar *ActionMainMenuBar1;
        void __fastcall HelpIndexExecute(TObject *Sender);
        void __fastcall FileNewExecute(TObject *Sender);
        void __fastcall FileOpen1Accept(TObject *Sender);
        void __fastcall FileSaveExecute(TObject *Sender);
        void __fastcall FileSaveAs1BeforeExecute(TObject *Sender);
        void __fastcall FileSaveAs1Accept(TObject *Sender);
private:	// User declarations
public:		// User declarations
        AnsiString FileName;
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
 
An Unresolved external error occurs if some part of your code attempts to call a function which has been declared but not defined:

Code:
void myfunc(); //Declare the function

void otherfunc()
{
    myfunc();
}

//For the above code to link correctly, myfunc() must be defined somewhere, for example:

void myfunc()
{
    //Do this
    //Do that
}

Your specific error can only be solved by defining the HelpIndexExecute method of your class. This could (in theory), be as little as adding this to your class definition:

Code:
void __fastcall TForm1::HelpIndexExecute(TObject* Sender)
{ /* Empty procedure */ }
 
Often the link errors mean the linker couldnt find a library it needs. That usually means you need to add a reference, or point to a library file (.LIB). Youll have to find out what library that function call exists in and add it to your project. I could help in VS.NET and VS 6.0 but Im not familiar with Borlands compiler.

Id search for something like extra directories (find the lib directories) and/or a place where you specify what LIB files to link to.

-Ner
 
Back
Top