Vladimir Panteleev
Vladimir Panteleev

Reputation: 25187

How to link Delphi with C++?

cpp.cpp

extern "C"
char* GetText()
{
  return "Hello, world!";
}

delphi.dpr

{$APPTYPE CONSOLE}

{$LINK 'cpp.obj'}
function _GetText: PChar; cdecl; external;

begin
  WriteLn(_GetText);
end.

I can't get this to work, no matter what I try. I tried various calling conventions, playing with underscores. even creating a .c wrapper for the .cpp code (but then the .c wrapper doesn't "see" any .cpp symbols). I'm about to give up and use DLLs. Any suggestions?

Upvotes: 3

Views: 1871

Answers (1)

Robert Love
Robert Love

Reputation: 12581

You have run into a limitation of the compiler.

These two articles cover your options in fairly good detail:

Upvotes: 2

Related Questions