Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-03

calling object pascal object function in c/c++

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Toan Pham

Hi,

I am working on calling object pascal functions from c/c++. I notice that when a unit is compiled into object code, the name of a function is altered in this convention:

<unit name>_<function name>$$<return type>

for example, if i have this unit:

unit wrapper;
interface
function test(): integer; stdcall;
implementation
function test(); integer; stdcall;
begin
    result := 3;
end;
end.

when the unit described above is compiled, its name changed to "WRAPPER_TEST$$SMALLINT",
not just test like c/c++ expects at link time. Is there a way perhaps through fpc compiler setting or using object pascal identifier to avoid object pascal name mangling like this?

Please help.

thank you.

Toan

Reply by email

Toan Pham
to Toan Pham: I am working on calling object pascal functions from c/c++. I notice that when a unit is…

I just find out the solution.
To make sure that fpc does not change function names after compilation, one has to add 'export' identifier to such functions. This would be the solution to the above example.

function test(): integer; stdcall; export;

I tested and it linked fine. One can also use the alias identifier to be able to have a new function name references FPC function.

Reply by email