OpenCV for C++ Builder Rad Studio 12.2

Hello ALL !

https://blogs.embarcadero.com/how-to-achieve-common-tasks-with-the-new-clang-toolchain-in-12-1/#Imports

Creating DLL Import Libraries

To import a random DLL, you need an import library. Any existing COFF one should work with our linker (this includes import libraries made by third parties for their DLLs, intended for use with MSVC.)

However, if you need to generate your own, you first need the definition (.def) file for the DLL. To do this, you can use the gendef.exe file from LLVM-MinGW. We aren’t shipping this yet, so you need to download it. Note that the following is third party and not verified or virus-checked by us, but the official llvm-mingw site recommends Martin Storsjö’s github for release. One release is: Release llvm-mingw 20220906 with LLVM 15.0.0 · mstorsjo/llvm-mingw · GitHub

This is only for creating x64 applications in RAD Studio.

According to this document, now in C++ Builder Rad Studio 12.2 it is possible to convert and connect third-party DLLs, including MSVC.

Does anyone have experience connecting OpenCV to the new Rad Studio?
Has anyone tried to do this?

I tried using this instruction to create *.def and *.lib files from the original OpenCV DLL MSVCRT. Everything works out, the *.def and *.lib files are created.

My code :

//---------------------------------------------------------------------------
#include <vcl.h>

#pragma hdrstop

#include "Unit1.h"

#include <opencv2/opencv.hpp>

#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/core/matx.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/core/utility.hpp>

using namespace cv;

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1* Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject* Sender)
{
	Mat image = imread("image.jpg");
}
//---------------------------------------------------------------------------

An error occurred during compilation:

[ld.lld Error] ld.lld: error: undefined symbol: cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, int)
[ld.lld Error] ld.lld: error: undefined symbol: cv::Mat::~Mat()

What’s wrong?

that looks like linker problems. you need to link the opencv core and imgcodecs libraries, or world which contains everything. which to link depends on what you have available.

this is what your compiler has, not what was built into the msvc dll
different string implementation → different function signature → name mangling mismatch

just out of curiosity: could you show us the .def file, please ?

Hello, friends!

Thank you for finding the opportunity to sort out the problem!

I connected the Lib files to my project, but the error remained.

For example, I posted the def and lib files of one of the libraries. If you need more information, please let me know.

opencv_world4100.def: opencv_world4100.def - Google Drive

opencv_world4100.lib: opencv_world4100.lib - Google Drive

For everything to work, you need to build the library (opencv + contrib) on this compiler from the source code. I built it a couple of years ago (the latest 4.7.0, I don’t remember what version of C++Builder it was at that time, you have to build it separately for each version of C++Builder). The first time you will need to spend a day on the revision. There is nothing complicated. And I built staticlib 32/64 and dll 32/64.

Hello Alexandr_S !

I have already spent a lot of time connecting OpenCV to RAD Studio. But I can’t do it in any way (

Here is my branch for 2003: Build with Embarcadero RAD Studio 11.3 Builder C++ error: use of undeclared identifier 'uintptr_t'

Could you help me with connecting this new version of OpenCV to RAD Studio 12.2? Maybe you can share the instructions ?

C++Builder v12.2 is now able to build opneCV from scratch without any motifications. Here is a link from David Millington from Embarcadero where he describes how to do it:

And this is not all. According to David Millington it’s also possible to build other 3rd Party Libraries like VTK and others. I am posting an image here of the demos already included with C++Builder v12.2. Hope this helps you

1 Like
rob-1982

C++Builder v12.2 is now able to build opneCV from scratch without any motifications. Here is a link from David Millington from Embarcadero where he describes how to do it:


Wow!

rob-1982 , this is what you need!
Thank you so much for the hint!

I am very grateful to you!

1 Like