Cross-platform OpenCV wrapper for Delphi and FreePascal with fully dynamic library loading
This project is a fork of Laex/Delphi-OpenCV, re-engineered to work on both Windows and Ubuntu Linux.
All OpenCV functions are bound dynamically at run-time (LoadLibrary / dlopen), so you can replace or remove the native libraries without recompiling the Pascal code.
- Delphi + FreePascal – one code-base, works with both compilers.
- Windows + Linux – tested on Windows x86 / x64 and Ubuntu x64.
- Dynamic loading – no static linking; pointers are resolved at run-time.
- Graceful fallback – if a
.dll/.sois missing, function pointers stayniland the application keeps running. - Self-contained Linux libs – every OpenCV
.sois built/patched with an internal RPATH ($ORIGIN), so the libraries inside the same folder can see each other withoutLD_LIBRARY_PATH.
-
Clone the repo
git clone https://github.com/pisarev/CrossOpenCV-FPC.git cd CrossOpenCV-FPC -
Fetch the native libraries
Download the correct archive from the Releases page (see below) or just run the helper script:# Linux ./scripts/download_binaries.sh # Windows (PowerShell) scripts\download_binaries.ps1
-
Compile
Delphi – open the project file and press Build.
FreePascal – for example:fpc src/examples/example.pas
The wrapper already contains the logic that calls
LoadLibrary/dlopenwith hard-coded paths.
Just place the libraries exactly as described below – no extra environment variables or RPATH tweaks are needed.
| Archive | Architecture |
|---|---|
opencv_2.4.13-win32.zip |
Win 32-bit |
opencv_2.4.13-win64.zip |
Win 64-bit |
-
Unzip next to your executable so the layout becomes
MyApp.exe └── opencv_2.4.13/ ├── opencv_core2413.dll ├── opencv_imgproc2413.dll └── … other DLLs -
Do not rename or move the
opencv_2.4.13folder – the Pascal code loads DLLs from
<exe_dir>/opencv_2.4.13/....
| Archive | Architecture |
|---|---|
opencv_2.4.13-linux-x86_64.tar.xz |
Linux x86-64 |
-
Extract the archive next to the executable so the layout becomes
/path/to/myapp (ELF executable) └── bin/ └── opencv_2.4.13/ ├── libopencv_core.so.2.4.13 ├── libopencv_core.so -> ./libopencv_core.so.2.4.13 └── … other .so + relative symlinks -
The wrapper calls
dlopen(<exe_dir>/bin/opencv_2.4.13/libopencv_*.so.2.4.13)so do not move the folder.
The archive is packed with tar.xz to preserve symbolic links, and every.soalready contains an$ORIGINRPATH, allowing the libraries in the same folder to resolve their mutual dependencies automatically. -
32-bit Linux is not supported in this fork.
cd /home/user
tar xJf opencv_2.4.13-linux-x86_64.tar.xz
./myapp # the program now loads all .so files from bin/opencv_2.4.13Expand-Archive opencv_2.4.13-win64.zip -DestinationPath 'C:\Projects\MyApp\opencv_2.4.13'
C:\Projects\MyApp\MyApp.exe # DLLs are loaded from .\opencv_2.4.13All native libraries live in the Releases section so the git repository stays small.
Direct download links (always point to the latest release):
| Platform | Asset |
|---|---|
| Windows 32-bit | https://github.com/pisarev/CrossOpenCV-FPC/releases/download/v1.0.0/opencv_2.4.13-win32.zip |
| Windows 64-bit | https://github.com/pisarev/CrossOpenCV-FPC/releases/download/v1.0.0/opencv_2.4.13-win64.zip |
| Linux 64-bit | https://github.com/pisarev/CrossOpenCV-FPC/releases/download/v1.0.0/opencv_2.4.13-linux-x86_64.tar.xz |
Distributed under the MPL 1.1. See the LICENSE file for details.
Create issues or pull requests on GitHub if you encounter problems or have improvements.