Jump to content
Al T

Is static linking of c++ libraries made with other compilers possible in Delphi?

Recommended Posts

I'm in a discussion with Skia4Delphi about this and was wondering if anyone here has tackled this problem?

 

Vinícius Felipe Botelho Barbosa says it's nearly impossible and well, I'm curious if anyone has done the impossible?

 

I have the Delphi 11.0 Enterprise Edition.

 

https://github.com/skia4delphi/skia4delphi/discussions/176#discussioncomment-4097532

 

Thanks for your help in advance!

 

Share this post


Link to post
11 hours ago, David Heffernan said:

Yes it's exceptionally hard. Just put the code in a DLL. 

I think David meant it's NOT exceptionally hard. However, you can't export C++ classes in your DLL. You must use simple structures (records) as parameters in your exported functions, ie structures that can be understood by other languages. The other thing to watch our for is memory management because structures created by DLL functions (ie heap allocoated memory) can't be freed using Delphi's memory manager.

Here is an example in my Polygon Clipping library and the C++ export header.

 

Edit: And of course Delphi routinely links to numerous operating system DLLs that would have been written in C and C++.

 

Edit2: I haven't properly researched this but it looks like Delphi's FreeMemory function bypasses Delphi's memory manager and frees heap memory directly. So FreeMemory could probably be used to free structures created by (C++) DLLs. Nevertheless, IMHO, all DLLs that create heap allocated structures - ie any structure returned as a pointer - should also export functions to destroy these structures.

 

Edit: The OP was asking about static linked libraries, and my reply was about dynamic libraries. Sorry.

Edited by angusj
  • Like 1

Share this post


Link to post
3 hours ago, angusj said:

I think David meant it's NOT exceptionally hard.

 No, I mean that linking C++ static libraries is exceptionally hard, because where do you get the runtime support from? 

 

3 hours ago, angusj said:

haven't properly researched this but it looks like Delphi's FreeMemory function bypasses Delphi's memory manager and frees heap memory directly.

No. It calls the standard Delphi MM. Also, there's no concept of freeing heap memory directly. That makes no sense. You always have to free from the same heap that was used to allocate. 

  • Like 1

Share this post


Link to post

Deleted post to avoid showing my ignorance :classic_wacko:.

 

(I confused static linking with static binding.)

Edited by angusj
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×