4

if I have a source of library written in C/C++ (lets say its libxml2), now I'd like to build it, and link it into the delphi application... I know it is possible, since Delphi Zlib does it ( http://www.dellapasqua.com/delphizlib/ ) ... But my question is, how to prepare those .obj files?

Thanks in advance m.

skaffman
  • 398,947
  • 96
  • 818
  • 769
migajek
  • 8,524
  • 15
  • 77
  • 116

2 Answers2

5

You would need to use CodeGear's C++ compiler to produce compatible obj files for Delphi. Does your Delphi come with C++ Builder? Otherwise you could try the free (Borland) commandline version. Read more about this subject here.

Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
  • I've already read that article. This however doesn't cover the topic of solving C standard library dependencies, I don't find it possible to re-implement so many C standard functions like open,read, recv, memcpy etc etc ... I believe there is a better solution than the one author did proposed. – migajek Dec 27 '09 at 18:16
  • Maybe it is best if update your question with this new information. Or ask a new question about this specific issue. – Lars Truijens Dec 27 '09 at 18:22
  • tip from Allen's article: add crtl.dcu to your project to solve core C RTL link issues. – Warren P Jan 04 '10 at 16:38
0

If you create a dll that adheres to the C Application Binary Interface (ABI), you can dynamically link to it from either a C++ or a Delphi Application.

It is advisable that you do the the following:

  1. Use only C or C style code, do yourself a favour and surround the module with

#ifdef __cplusplus
extern "C"
{
//header file
}
#endif //__cplusplus

This guarantees that the code compiles into the C ABI

  1. it is advisable to make the functions __stdcall

  2. Compile the function as a dll

from here you should be able to link to the dll in the same way that Delphi can link to any windows DLL. (I can't remember what needs to be done from the Delphi side)

doron
  • 27,972
  • 12
  • 65
  • 103