4

I compiled libxml2 with BCC 5.5 command line compiler, now I have lots of .obj files which I'd like to link into my Delphi application. Unfortunately, I get lots of "Unsatisfied forward or external declaration" errors, pointing to standard C library functions like memcpy, open, recv etc ... What should I do to compile it correctly? I'd like to avoid depending on msvcrt.dll or any other external libraries.

Thanks in advance!

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

3 Answers3

14

Depending on the version of Delphi you have, there should be a unit called crtl.dcu with which you can link. Just use the $L directive for each .obj file in a unit that also uses crtl. You may also need to "use" other various units like Windows, WinSock, etc... The point is to provide the symbols and functions to resolve during the link phase.

This is the same technique used to statically link in the DataSnap TClientDataSet code used to also build midas.dll.

Allen Bauer
  • 16,657
  • 2
  • 56
  • 74
3

you should read article of Rudy here "Using C object files in Delphi"

flashvnn
  • 273
  • 6
  • 15
  • 1
    Welcome to Stack Overflow. That's a good article, but to make this a better answer, you should explain *why* that's a good article to read. Tell what to expect. In particular, that article describes two techniques for solving the problem. One is to manually implement all the missing functions. (The article demonstrates.) The other way is to link with msvcrt.dll, which already has implementations of all the missing functions. (The article demonstrates that, too.) The second way is especially good for functions like `printf`, which can't be implemented easily in Delphi. – Rob Kennedy Dec 28 '09 at 17:32
  • Also, MSVC++ can be compiled with asm producing option and then ml.exe makes needed obj to $L in Delphi. – Sergei Krivonos Jan 31 '20 at 14:26
0

Don't use those functions, but rewrite them to call operating system functions (kernel32/system32) directly.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89
  • the C code I'm compiling is libxml2 which is quite complex, I'd like to avoid any changes there. – migajek Dec 27 '09 at 19:51
  • @michal: You are aware that there are a couple of dozen free Delphi wrappers available for LibXML2, right? Here's one, recommended by Marco Cantu: http://sourceforge.net/projects/libxml2-pas. Marco's blog recommendation for this implementation can be found at http://blog.marcocantu.com/blog/delphicomps.html – Ken White Dec 29 '09 at 14:48
  • For which libxml2 exactly? There are heaps of builds. – Marco van de Voort Dec 29 '09 at 21:01
  • Huh I had no idea ... the one checked out from libxml2 page? – migajek Dec 31 '09 at 13:30
  • Ken I know that. I just want to avoid additional dlls. – migajek Dec 31 '09 at 13:32