• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 623
  • Last Modified:

Using C++Builder code in Delphi

I am trying to use the {$L xxxx.obj} documented feature with Delphi 4.

The OBJ file is generated with C++Builder 4.

I get the following error message :

Unsatisfied forward declaration or uncorrect external declaration.

Can someone tell me why ? I am thinking of a problem of correspondence between Delphi and C++ types...
0
godcha
Asked:
godcha
  • 4
  • 3
1 Solution
 
godchaAuthor Commented:
Edited text of question.
0
 
godchaAuthor Commented:
Edited text of question.
0
 
intheCommented:
did you specify the correct path? :

{$L myprogramdir/test/testing.obj}
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
intheCommented:
Note, however, that this will only work if you have _not_ used any of the C
runtime library routines in the C++ code, and won't work with
C++ classes contained in the OBJ.


the following was a test with a teamb bloke a last year with another bloke having same problem as you and generates same error:

C (compiles to cobj.obj);
--------------------------------------------------------
//cobj source for newsgroup post
 
//function prototype
extern "C" void __stdcall thefunction();
 
//function implementation
void __stdcall thefunction(){
  return;
}
 
//end of C source
-----------------------------------------------------------
Delphi unit (only unit of project1.exe):
-----------------------------------------------------------
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,   StdCtrls;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.DFM}
{$L cobj.obj}
procedure thefunction; stdcall; far; external;
 
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  thefunction;
end;
 
end.
----------------------------------------------------------------------------
 
When trying to compile, the only error message is this:
"unsatisfied forward or external declaration: thefunction"



but when changing the c routine to:


 #pragma option push -V?-
//undocumented stuff

extern "C" void __stdcall thefunction();

//function implementation
void __stdcall thefunction(){
  return;
}
 
#pragma option pop


it them compiled and worked and delphi found the function...maybe it help you ?
hope so
Regards Barry
0
 
LischkeCommented:
In additionto Barry's comment:

Some C library functions can quite easily emulated. If you need that I can provide these functions:

function _malloc(Size : Integer): Pointer; cdecl;
procedure _free(Ptr : Pointer); cdecl;
function _calloc(NItems : Integer; Size : Integer) : Pointer; cdecl;
function _realloc(block : Pointer; Size : Integer) : Pointer; cdecl;

function _strcat(Dest, Source: PChar): PChar; cdecl;
function _strlen(P1: PChar): Integer; cdecl;
function _strcpy(Dest, Source: PChar): PChar; cdecl;
function _strncmp( const s1 : Pchar;
                   const s2 : Pchar; maxlen : Integer) : Integer; cdecl;
function _strncpy( dest : Pchar;
                   const src : Pchar; maxlen : Integer) : PChar; cdecl;
function _strtok(const s1 : PChar; const s2 : PChar) : PChar; cdecl;

function _tolower( ch : Integer ) : Integer; cdecl;

procedure _memset(P: Pointer; Value: Integer; Count: Cardinal); cdecl;

function _memcpy(Dest, Source: Pointer; Len: Integer): Pointer; cdecl;
function _memcmp( const s1   : PByteArray;
                  const s2   : PByteArray;
                  const Size : Integer  ): Integer; cdecl;

function _ltoa(Value : LongInt; Str : PChar; Radix : Integer) : PChar; cdecl;
function _exp( value : double ) : double; cdecl;
function _floor( value : double ) : double; cdecl;
function _log( value : double ) : double; cdecl;
function _sqrt( value : double ) : double; cdecl;
function _fabs( value : double) : double; cdecl;
function _pow( x : double; y : double ) : double; cdecl;

procedure __turboFloat; cdecl;
procedure __streams; cdecl;


It's a unit of ~600 lines and I got it with an uncomplete PNG implementation from Zwabbert. Note: I haven't tried the code yet!

Whoever needs the code call me at public@lischke-online.de.

Ciao, Mike
0
 
intheCommented:
some ti's on the matter

http://www.borland.com/devsupport/bcppbuilder/ti/TI2431C.html


there is a delphi ti as well but i could'nt find it.
0
 
godchaAuthor Commented:
To Inthe

Why won't it work with code using C runtime library routines ?
0
 
intheCommented:
Hi
 i have no idea why not but it came from a teamb member and they usually know what they are are on about ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now