OpenCV With C++ Builder

Use of OpenCV in Borland's C++ Builder in Microsoft Windows can be described in two main ways. You can either use the released .libs and .dlls directly or you can recompile OpenCV from source.

Use the released .libs and .dlls directly

The import libraries (.libs) and dynamic link (.dlls) libraries contained in the OpenCV release for Windows were made with Visual C++. Unfortunately, VC++ and BC++ use binary incompatible formats for import libraries and the calling conventions differ as well (and the difference is not just a matter of fastcall, cdecl or stdcall, because BC++ puts an extra argument on the stack - making cvGetSize() and possibly more functions complain).

Convert the import libraries

BC++ comes with the command line utility coff2omf. Here is a (Cygwin bash) shell command to achieve the conversion of all .libs (it is equally possible to do this with some Windows script). Run it in the lib subdirectory of the OpenCV installation directory:

#!/bin/sh
mkdir -p borland
for i in *.lib; do coff2omf $i borland/$i; done

Now the import libraries in lib\borland can be used by BC++ - just add them to your project.

Get the calling conventions right

bcc32.exe has a switch (among many others): -VM for Microsoft Visual C++ compatibility (see the output of bcc32 -h -V). Its corresponding IDE option (at least in Borland Developer Studio 2006) can be found under source under C++ options of the project options.

What exactly does -VM do? It looks as if there is a difference in how return values using stdcall return values are handled. Unfortunately, there is no documentation readily available.

BC++ sample project

The attached file from Luiz Reginaldo contains a functional project in C++ Builder 5.0 environment. The project uses OpenCV library and Forms. The attached file contains all the opencv .h, .lib and .dll files required to run the application. He hopes this can be useful to you. I have not tried it, but he did not find out about -VM, because he avoided cvGetSize().

Download the Project file: OpenCV_Builder.zip

Recompile OpenCV from source

_make\make_all_bc.mak from the OpenCV installation directory might help in this, otherwise you have to put all source files into new projects.

C++Builder (last edited 2008-03-03 16:35:22 by MichaelBunk)

SourceForge.net Logo