Friday, January 19, 2007

C++: LibXML in Borland C++ Builder 5

The key to this solution is using a command-line utility that comes with BCB5 called implib.exe which creates a borland-type .lib file from a win32 .dll

Goal:
Get a simple C++ libxml code example to work (from http://xmlsoft.org/examples/index.html)

What to do:
Okay the first thing you need to do is download win32 libxml from http://www.zlatkovic.com/libxml.en.html

but it has certain dependencies so you will want to fetch the binaries:
* libxml2, the XML parser and processor.
* libxslt, the XSL and EXSL Transformations processor.
* xmlsec, the XMLSec and XMLDSig processor.
* xsldbg, the XSL Transformations debugger.
* openssl, the general crypto toolkit.
* iconv, the character encoding toolkit.
* zlib, the compression toolkit.

Then you three types of files in each project, .dll .lib and .h. The problem with these .lib files is that these .lib files are compiled for Microsoft Visual Studio. But in borland the way to create lib files is using implib.exe included in all distributions of borland c++ builder. I run

implib.exe -a zlib.lib zlib.dll

to create a zlib.lib for borland. Then I do the same thing for the other dlls.

Then add the .lib into the borland project and then source code examples will work.

Hooray for implib!

source(s)
http://www.gantless.com/borland.html (implib)
http://www.zlatkovic.com/libxml.en.html (libxml)
http://xmlsoft.org/examples/index.html (libxml examples)

2 comments:

Raul said...

Hello, first, sorry for my bad english.

I have Borland C++ 5.02, and libxml2.

I have the next error :


Error: Error: 'C:\PROJECTS\LIBXML\LIB\LIBXML2_A.LIB' contains invalid OMF record, type 0x21


How can I repair this?

Thanks

marker said...

Raul, this .lib file was built for Visual C++. The way to build a borland .lib file is find the borland utility implib.exe, (usually in the bin folder) from the command line run "implib.exe -a libxml.lib libxml.dll" (or whatever the name of the .dll file is) it will generate a Borland .lib file (libxml.lib) file that you can use.

You can also look at Troubleshooting #4 at:
http://www.gantless.com/borland.html