Question

I want to link statically a Delphi function from a C++Builder source. I added the .pas file to the C++Builder project. I tried the following declarations:

In Delphi:

procedure SayHi; stdcall;

In C++Builder:

extern "C" {
    void __stdcall SayHi();
}

All modules compile fine, but when I link it I get the following error:

[ilink64 Error] Error: Unresolved external 'SayHi' referenced from C:\DEV\PACKSWAP\WIN64\DEBUG\MAIN.O

What am I missing?

Was it helpful?

Solution

When you compile a .pas file in a C++Builder project, an .hpp header file is automatically created that you can then #include in your C++ code where needed. There is no need to declare the function manually.

The linker error is due to your use of extern "C" on the C++ side. That is affecting how the C++ compiler emits name mangling/decoratation for that function, so it does not match the name mangling/decoration that the Delphi compiler emits. That is why the linker cannot find the function implementation. Remove the extern "C" and then both compilers should emit the same name mangling/decoration to allow the linker to match them up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top