# OpenCV for C++ Builder Rad Studio 12.2

**URL:** <https://forum.opencv.org/t/opencv-for-c-builder-rad-studio-12-2/18882>\
**Category:** C++\
**Tags:** embarcadero\
**Created:** [October 4, 2024, 12:49am UTC](https://forum.opencv.org/t/opencv-for-c-builder-rad-studio-12-2/18882 "2024-10-04T00:49:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Acronis](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Acronis](https://forum.opencv.org/u/Acronis)\
**Post date:** [October 4, 2024, 12:49am UTC](https://forum.opencv.org/t/opencv-for-c-builder-rad-studio-12-2/18882/1 "2024-10-04T00:49:52Z")

</div>

Hello ALL !

[https://blogs.embarcadero.com/how-to-achieve-common-tasks-with-the-new-clang-toolchain-in-12-1/#Imports](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](https://github.com/mstorsjo/llvm-mingw/releases/tag/20220906)

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 :

```auto
//---------------------------------------------------------------------------
#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:

```auto
[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?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 4, 2024, 7:22am UTC](https://forum.opencv.org/t/opencv-for-c-builder-rad-studio-12-2/18882/2 "2024-10-04T07:22:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [October 4, 2024, 12:00pm UTC](https://forum.opencv.org/t/opencv-for-c-builder-rad-studio-12-2/18882/3 "2024-10-04T12:00:02Z")

</div>

> [@Acronis](#):
>
> `std::__1::basic_string`

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 ?

---

<div class="post-metadata">

**Author:** ![Acronis](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Acronis](https://forum.opencv.org/u/Acronis)\
**Post date:** [October 4, 2024, 11:13pm UTC](https://forum.opencv.org/t/opencv-for-c-builder-rad-studio-12-2/18882/4 "2024-10-04T23:13:55Z")

</div>

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](https://drive.google.com/file/d/1d4j2iZYCWRTHSwAWZoVt8Y00d6wuLpgx/view?usp=sharing)

opencv\_world4100.lib: [opencv\_world4100.lib - Google Drive](https://drive.google.com/file/d/1-oYSjZroiv5lCLiBWp58sq2wTDlMadfj/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![Alexandr\_S](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/alexandr_s/32/11263_2.png) [@Alexandr\_S](https://forum.opencv.org/u/Alexandr_S)\
**Post date:** [October 15, 2024, 9:50am UTC](https://forum.opencv.org/t/opencv-for-c-builder-rad-studio-12-2/18882/5 "2024-10-15T09:50:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Acronis](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Acronis](https://forum.opencv.org/u/Acronis)\
**Post date:** [October 15, 2024, 11:32pm UTC](https://forum.opencv.org/t/opencv-for-c-builder-rad-studio-12-2/18882/6 "2024-10-15T23:32:49Z")

</div>

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'](https://forum.opencv.org/t/build-with-embarcadero-rad-studio-11-3-builder-c-error-use-of-undeclared-identifier-uintptr-t/13618)

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

---

<div class="post-metadata">

**Author:** ![rob-1982](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@rob-1982](https://forum.opencv.org/u/rob-1982)\
**Post date:** [November 25, 2024, 5:21pm UTC](https://forum.opencv.org/t/opencv-for-c-builder-rad-studio-12-2/18882/7 "2024-11-25T17:21:43Z")

</div>

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:

> **[Introducing Amazing CMake Support in C++Builder 12.2](https://blogs.embarcadero.com/introducing-amazing-cmake-support-in-cbuilder-12-2/)**
>
> C++Builder and RAD Studio 12.2 bring a fantastic feature for C++: full CMake support for the new Win64 Modern toolchain. It’s available in GetIt now, and it comes with some amazing demos. You can build VCL apps, FMX apps, packages, DLLs, console...

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

 ![c++Builder](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/d/da1f8d6bcfa03c66524ce3c0514da4362974e7b7.png)

---

<div class="post-metadata">

**Author:** ![Acronis](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Acronis](https://forum.opencv.org/u/Acronis)\
**Post date:** [November 25, 2024, 11:43pm UTC](https://forum.opencv.org/t/opencv-for-c-builder-rad-studio-12-2/18882/8 "2024-11-25T23:43:42Z")

</div>

```auto
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!
