Board index » cppbuilder » Problem calling a function from another unit.

Problem calling a function from another unit.


2003-12-04 10:33:44 AM
cppbuilder23
Hi,
This has been troubling me for a couple of days. I want to call a function
'test()' (which has been coded in Unit2.c) from Unit1. I can email you an
example program which causes the problem if nessecearry. Thanks in advance.
When I compile I get an error message like this:
[Linker Error] Unresolved external 'test()' referenced from
C:\windows\desktop\test\unit1.obj
=[file is unit1.c]================================================
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button1Click(TObject *Sender)
{
test();
}
//--------------------------------------------------------------------------
-
=[file is unit2.c]====================================================
#include "Unit2.h"
void test(void)
{
char i;
i=1;
i=i+1;
}
==[file is unit2.h]===================================================
#ifndef Unit2_H_
#define Unit2_H_
void test(void);
#endif
 
 

Re:Problem calling a function from another unit.

Yep, certainly did.
Quote

Did you add Unit2.c to your project? By the way, Unit1.c should (probably)
be named Unit1.cpp...

Regards,
Bruce


 

Re:Problem calling a function from another unit.

Quote
This has been troubling me for a couple of days. I want to call a function
'test()' (which has been coded in Unit2.c) from Unit1. I can email you an
example program which causes the problem if nessecearry. Thanks in
advance.
Did you add Unit2.c to your project? By the way, Unit1.c should (probably)
be named Unit1.cpp...
Regards,
Bruce
 

{smallsort}

Re:Problem calling a function from another unit.

You might try getting rid of the void in the parameter list.
void test();
void test()
{
//implementation
}
 

Re:Problem calling a function from another unit.

"JunkMail" < XXXX@XXXXX.COM >wrote in message
Quote
You might try getting rid of the void in the parameter list.
There is nothing wrong with having 'void' as the parameter. It is perfectly
legal to do so.
Gambit
 

Re:Problem calling a function from another unit.

Has any one else try the following code? I'm not sure if it is just my
compiler version.
Quote

When I compile I get an error message like this:
[Linker Error] Unresolved external 'test()' referenced from
C:\windows\desktop\test\unit1.obj






=[file is unit1.c]================================================
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//--------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
test();
}
//--------------------------------------------------------------------------
=[file is unit2.c]====================================================
#include "Unit2.h"
void test(void)
{
char i;
i=1;
i=i+1;
}
==[file is unit2.h]===================================================
#ifndef Unit2_H_
#define Unit2_H_
void test(void);
#endif
 

Re:Problem calling a function from another unit.

Hi!
nobody wrote:
Quote
Has any one else try the following code? I'm not sure if it is just my
compiler version.
Unless I define Unit2_H_ in my project options, it works. I can only
think of this: the unit2.CPP is not added to the project (via
project|add to project...). It does not help, if you only added the header.
Frank
 

Re:Problem calling a function from another unit.

Thank you very much for the comment, i have added unit2.c but it dosn't work
for me.
Which version of borland are you running?
Does it matter that I'm calling it unit2.c instead of unit2.cpp?
"Frank Birbacher" < XXXX@XXXXX.COM >wrote in message
Quote
Hi!

nobody wrote:
>Has any one else try the following code? I'm not sure if it is just my
>compiler version.

Unless I define Unit2_H_ in my project options, it works. I can only
think of this: the unit2.CPP is not added to the project (via
project|add to project...). It does not help, if you only added the
header.

Frank