tags:

views:

408

answers:

3

Hi, 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!

A: 

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

Marco van de Voort
the C code I'm compiling is libxml2 which is quite complex, I'd like to avoid any changes there.
migajek
@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
For which libxml2 exactly? There are heaps of builds.
Marco van de Voort
Huh I had no idea ... the one checked out from libxml2 page?
migajek
Ken I know that. I just want to avoid additional dlls.
migajek
+7  A: 

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
unfortunately, there is no crtl unit in my Delphi installation... it's Delphi7 PE.
migajek
Sounds like an excellent reason to upgrade to at least D2007 ;-)
Allen Bauer
+1. Cool tip. Thanks Allen.
Warren P
+1  A: 

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

flashvnn
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