Linking error with exit code 2 CMake opencv embarcadero C++ builder 10.3

I need to use OpenCV in embarcadero C++ builder 10.3 and to do that I use CMake and the following command to create the borland makefiles:

cmake -DCMAKE_C_COMPILER=bcc32x.exe -DCMAKE_CXX_COMPILER=bcc32x.exe -DCMAKE_CXX_FLAGS="-Wno-c++11-narrowing" -G"Borland Makefiles" -DCMAKE_BUILD_TYPE=Debug -DBUILD_OPENEXR=OFF -DBUILD_opencv_world=OFF -DBUILD_PERF_TESTS=OFF -DWITH_WEBP=OFF -DWITH_OPENCL=OFF -DWITH_FFMPEG=OFF -DWITH_OPENEXR=OFF -DWITH_TIFF=OFF -DBUILD_opencv_objdetect=OFF -DBUILD_TIFF=OFF -DBUILD_TESTS=OFF -DWITH_JASPER=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_PROTOBUF=OFF -DBUILD_opencv_dnn=OFF -DBUILD_IPP=OFF -DWITH_IPP=OFF -DWITH_ADE=OFF  C:/openCV/opencv-4.5.3

After it finished building and generating I used the command make install to create the makefiles but I get an error when it tries to link saying:

[ 97%] Linking CXX executable ..\..\bin\opencv_annotationd.exe
Embarcadero C++ 7.40 for Win32 Copyright (c) 2012-2018 Embarcadero Technologies, Inc.
Embarcadero Technologies Inc. bcc32x version 5.0.2 (36752.0cce431.9f79754) (based on LLVM 5.0.2)
Target: i686-pc-windows-omf
Thread model: posix
InstalledDir: C:\Program Files (x86)\Embarcadero\Studio\20.0\bin
bcc32x.exe: warning: argument unused during compilation: '-nobuiltininc' [-Wunused-command-line-argument]
 "\"C:\\Program Files (x86)\\Embarcadero\\Studio\\20.0\\bin\\ilink32.exe\"" "@\"C:\\Users\\xanderv\\AppData\\Local\\Temp\\opencv_annotationd-63732a.cfg\""
Turbo Incremental Link 6.90 Copyright (c) 1997-2017 Embarcadero Technologies, Inc.
Fatal: Unable to open file '....LIBOPENCV_CORE453D.LIB'
bcc32x.exe: error: linker command failed with exit code 2 (use -Xdriver -v to see invocation)

** error 2 ** deleting bin\opencv_annotationd.exe

** error 1 ** deleting apps\annotation\CMakeFiles\opencv_annotation.dir\all

** error 1 ** deleting all

I always get that error when trying to use the make install command and when trying to search if it is on my computer, it can’t be found anywhere. I don’t get the error when I use the ninja command like it is explained here. But when using ninja I don’t get it working like I explained in this problem.
This error occurs every time it wants to link exe files. How can I fix this error?

that’s a lib build by MSVisual Studio, unusable with your compiler. how did it get there ?

you probably don’t need it (for now).
try to disable APPS with

cmake -DBUILD_opencv_apps=OFF

NO PERSON EVER MANAGED TO USE THIS SUCCESSFULLY
(can we talk you out of using it ? 32bits, srsly ?)

1 Like

Thanks for the reply, after adding -DBUILD_opencv_apps=OFF it built correctly in the build folder. From the build folder I added the lib folder to tools->options->Language->C++ Options->Paths and Directories->Library Path. In …->Paths and Directories->System Include Path I added the install folder of the build folder and the include of that install folder. After that I added all the lib files from the staticlib folder of the install folder to the project folder of the project I want to test. But when I want to test if I can use OpenCV by using a simple line of code Mat frame; I get the following error:

[ilink32 Error] Error: Unresolved external 'cv::Mat::Mat()' referenced from C:\USERS\XANDERV\DOCUMENTS\GIT\APPLICATION SOFTWARE\OPENCVTEST\WIN32\DEBUG\MAIN.OBJ
[ilink32 Error] Error: Unresolved external 'cv::Mat::{1173}...' referenced from C:\USERS\XANDERV\DOCUMENTS\GIT\APPLICATION SOFTWARE\OPENCVTEST\WIN32\DEBUG\MAIN.OBJ
[ilink32 Error] Error: Unable to perform link

Sadly the project I need to add OpenCv to is created in WIN32 and want to see if it can be possible to be added for WIN32. Is the error because I use WIN32 or did I not correctly add the lib files to the project?

congratulations !
you got way further than the other dozen or so ppl trying before !

opencv_core missing somehow somewhere.
there is probably a (generated) linker cmdline, can you show it ?
if you’re linking static libs, order matters , so everything depending on core should go before that with linking (else you get unexplainable errors like above !)

This is the text that is under the ilink32 command line:

  c:\program files (x86)\embarcadero\studio\20.0\bin\ilink32.exe -G8 -L.\Win32\Debug;"c:\program files (x86)\embarcadero\studio\20.0\lib\Win32\debug";
  "C:\OpenCV\opencv-4.7.0\build\install\staticlib";"..\..\..\GIT\Application Software\OpenCVTest";"C:\OpenCV\opencv-XE7\build\lib";
  "C:\OpenCV\opencv-XE7\build\bin";"c:\program files (x86)\embarcadero\studio\20.0\lib\win32c\release";"c:\program files 
  (x86)\embarcadero\studio\20.0\lib\win32\release";"c:\program files (x86)\embarcadero\studio\20.0\lib\win32\release\psdk";"C:\Program Files 
  (x86)\DevExpress\VCL\Library\RS26";C:\Components\RVMediaVCL\Source;"C:\OpenCV\opencv-4.7.0\build\lib";
  C:\Users\Public\Documents\Embarcadero\Studio\20.0\DCP -j.\Win32\Debug;"c:\program files (x86)\embarcadero\studio\20.0\lib\Win32\debug";
  "C:\OpenCV\opencv-4.7.0\build\install\staticlib";"..\..\..\GIT\Application Software\OpenCVTest";"C:\OpenCV\opencv-XE7\build\lib";
  "C:\OpenCV\opencv-XE7\build\bin";"c:\program files (x86)\embarcadero\studio\20.0\lib\win32c\release";"c:\program files 
  (x86)\embarcadero\studio\20.0\lib\win32\release";"c:\program files (x86)\embarcadero\studio\20.0\lib\win32\release\psdk";"C:\Program Files 
  (x86)\DevExpress\VCL\Library\RS26";C:\Components\RVMediaVCL\Source;"C:\OpenCV\opencv-4.7.0\build\lib";
  C:\Users\Public\Documents\Embarcadero\Studio\20.0\DCP -l.\Win32\Debug -v -Gn 
  -GA"C:\Users\xanderv\AppData\Local\Temp\vfs11C8.tmp"="C:\Users\xanderv\Documents\GIT\Application Software\OpenCVTest\Main.dfm" -aa -V5.0 -Tpe c0w32w 
  rtl.bpi vcl.bpi memmgr.lib sysinit.obj .\Win32\Debug\OpenCVTest.obj .\Win32\Debug\Main.obj , .\Win32\Debug\OpenCVTest.exe , 
  .\Win32\Debug\OpenCVTest.map , ittnotifyd.lib "libjpeg-turbod.lib" libopenjp2d.lib libpngd.lib opencv_aruco470d.lib opencv_bgsegm470d.lib 
  opencv_bioinspired470d.lib opencv_calib3d470d.lib opencv_ccalib470d.lib opencv_core470d.lib opencv_datasets470d.lib opencv_dpm470d.lib 
  opencv_face470d.lib opencv_features2d470d.lib opencv_flann470d.lib opencv_fuzzy470d.lib opencv_hfs470d.lib opencv_highgui470d.lib 
  opencv_imgcodecs470d.lib opencv_imgproc470d.lib opencv_img_hash470d.lib opencv_intensity_transform470d.lib opencv_line_descriptor470d.lib 
  opencv_ml470d.lib opencv_objdetect470d.lib opencv_optflow470d.lib opencv_phase_unwrapping470d.lib opencv_photo470d.lib opencv_plot470d.lib 
  opencv_quality470d.lib opencv_rapid470d.lib opencv_reg470d.lib opencv_rgbd470d.lib opencv_saliency470d.lib opencv_shape470d.lib opencv_stereo470d.lib 
  opencv_stitching470d.lib opencv_structured_light470d.lib opencv_superres470d.lib opencv_surface_matching470d.lib opencv_tracking470d.lib 
  opencv_video470d.lib opencv_videoio470d.lib opencv_videostab470d.lib opencv_xfeatures2d470d.lib opencv_ximgproc470d.lib opencv_xobjdetect470d.lib 
  opencv_xphoto470d.lib quircd.lib zlibd.lib import32.lib cp32mti.lib , , OpenCVTest.res 
1 Like

any chance you can reorder this ?

  • put ALL 3rdparty libs (ittnotify, png, jpg, zlib, …) to the back
  • reorder opencv_XXX libs, so that part ends with opencv_imgproc470d.lib opencv_core470d.lib

gl, report back, please !

I have tried to reorder the libraries but I have not yet found a way to do that. It keeps ordering it alphabetically so I thought to create the opencv_world.lib file and try if that would work. To do that I added to the CMake command:

-DBUILD_opencv_world=ON

After generating and buidling the files and running make install I get the following error when it tries to link the opencv_world library:

Error: the combinations '+*' or '*+' are not allowed

Along with a lot of warnings that looks like this:

Warning: duplicate file 'rc' in list, not added!
Warning: unknown command line switch 'o' ignored

Do I need to add something to the CMake command or is it not possible for borland makefiles?

yea, makes a lot of sense

sorry, i have no idea

Sadly I can’t get it working for 32 bit so changed it to 64 bit. I used the following command to build the MakeFiles:

cmake -DCMAKE_C_COMPILER=bcc64.exe -DCMAKE_CXX_COMPILER=bcc64.exe -DCMAKE_CXX_FLAGS=“-Wno-c++11-narrowing” -G"Borland Makefiles" -DCMAKE_BUILD_TYPE=Debug -DBUILD_PERF_TESTS=OFF -DWITH_WEBP=OFF -DWITH_OPENEXR=OFF -DWITH_TIFF=OFF -DBUILD_TIFF=OFF -DBUILD_TESTS=OFF -DWITH_JASPER=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_PROTOBUF=OFF -DBUILD_opencv_dnn=OFF -DBUILD_IPP=OFF -DWITH_IPP=OFF -DWITH_ADE=OFF -DBUILD_opencv_apps=OFF C:\openCV\opencv-4.7.0

But when I run make install I get the following error when it tries to link opencv_core:

Error: unable to read ‘CMakeFiles.o’

** error 1 ** deleting lib\opencv_core470d.lib

** error 1 ** deleting modules\core\CMakeFiles\opencv_core.dir\all

** error 1 ** deleting all

It has the same kind of warnings as when I try to use opencv_world in 32 bit. How can I solve this problem?

I found out that I get this error because the lib file for opencv_core is completely empty. Did I do something wrong with the CMake command or is there another problem?

that looks sus.

anything named CMakeFiles is not compilable.

.o implies that either (1) the compiler was told to compile something of that name or (2) something expects that file to be compiled, which obviously makes no sense.

When trying to run opencv for embarcadero C++ builder 10.3 I changed a few things in the folder of OpenCV:

error: use of undeclared identifier ‘uintptr_t’ = add #include in …\opencv-4.7.0\3rdparty\ittnotify\include\ittnotify.h

error: use of undeclared identifier ‘lrintf’ = add #include <math.h> in …/opencv-4.7.0/modules/core/include\opencv2/core/fast_math.hpp

error: unknown type name ‘FILE’ = add #include <stdio.h> in …/opencv-4.7.0/modules/core/include\opencv2/core/operations.hpp

error: use of undeclared identifier ‘llvm’ = comment it out and make it return 0; instead in …/opencv-4.7.0/modules/core/include\opencv2/core/hal/intrin.hpp

error: token is not a valid binary operator in a preprocessor subexpression in #if (i64_fromNaN != i64_fromPosOverflow) || (i64_fromNaN != i64_fromNegOverflow) = comment out:
#if (i64_fromNaN != i64_fromPosOverflow) || (i64_fromNaN != i64_fromNegOverflow)
if ((exp == 0x7FF) && sig) {
#if (i64_fromNaN == i64_fromPosOverflow)
sign = 0;
#elif (i64_fromNaN == i64_fromNegOverflow)
sign = 1;
#else
raiseFlags(flag_invalid);
return i64_fromNaN;
#endif
}
#endif in …\opencv-4.7.0\modules\core\src\softfloat.cpp

My guess the reason why the core lib is empty is because of one of the changes I made to the files. I could solve three errors by adding an header to the code, but I don’t know how to solve the last two errors. The error messages from RAD studio prompt about the last two errors is shown below:
llvm:

[ 5%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/algorithm.cpp.obj
Embarcadero C++ 7.40 for Win32 Copyright (c) 2012-2018 Embarcadero Technologies, Inc.
C:\OpenCV\opencv-4.7.0\modules\core\src\algorithm.cpp:
In file included from C:\OpenCV\opencv-4.7.0\modules\core\src\algorithm.cpp:43:
In file included from C:\OpenCV\opencv-4.7.0\modules\core\src/precomp.hpp:88:
C:/OpenCV/opencv-4.7.0/modules/core/include\opencv2/core/hal/intrin.hpp:83:9: error: use of undeclared identifier ‘llvm’
return llvm.cttz.i32(value, true);
^
1 error generated.

** error 1 ** deleting modules\core\CMakeFiles\opencv_core.dir\src\algorithm.cpp.obj

** error 1 ** deleting modules\core\CMakeFiles\opencv_core.dir\all

** error 1 ** deleting all

i64_fromNaN:

[ 14%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/softfloat.cpp.obj
Embarcadero C++ 7.40 for Win32 Copyright (c) 2012-2018 Embarcadero Technologies, Inc.
C:\OpenCV\opencv-4.7.0\modules\core\src\softfloat.cpp:
C:\OpenCV\opencv-4.7.0\modules\core\src\softfloat.cpp:2051:6: error: token is not a valid binary operator in a
preprocessor subexpression
#if (i64_fromNaN != i64_fromPosOverflow) || (i64_fromNaN != i64_fromNegOverflow)
^~~~~~~~~~~
C:\OpenCV\opencv-4.7.0\modules\core\src\softfloat.cpp:327:40: note: expanded from macro ‘i64_fromNaN’
#define i64_fromNaN UINT64_C( 0x7FFFFFFFFFFFFFFF )
^~~~~~~~~~
C:/PROGRA~2/EMBARC~1/Studio/20.0/include/windows/crtl\stdint.h:211:33: note: expanded from macro ‘UINT64_C’
#define UINT64_C(x) ((uint64_t) x)
~~~~~~~~~~ ^
1 error generated.

** error 1 ** deleting modules\core\CMakeFiles\opencv_core.dir\src\softfloat.cpp.obj

** error 1 ** deleting modules\core\CMakeFiles\opencv_core.dir\all

** error 1 ** deleting all

What should I do to solve these errors and is commenting out the place where the error occurs the reason why my core lib is empty?

Another question about 64 bit, I downloaded the windows file from the site and got a .lib file of world. Except for Embarcadero C++ Builder 64 bit it needs to be .a file. Is there an easy way to change a lib file from .lib to .a?

I have tried lib2a but when I link the .a file I get the following error (object name may differ):

[ilink64 Error] Fatal: Invalid object file ‘dkpit.o’

After downgrading my OpenCV version to 2.4.13 and running the CMake command adding that contrib and legacy need to be turned off I have successfully downloaded the OpenCV lib files and have added them to C++ builder. Using those lib files, I could create a Mat file where I read an image. But when I want to try imshow to show the image I get the error saying that “[bcc32c Error] Main.cpp(26): C++ requires a type specifier for all declarations”. How can I solve this error?

Hi. Can you share your C++ Builder project ?

Sorry, completely forgot to reply.
I use 10.3 C++ Builder so maybe it is better to just try and build the lib files yourself. For me I used the mostly the same command as I used for 4.7.0 but I removed the extra modules. If you encounter any errors let me know and maybe I can help you.

Thanks.

I hope we will be able to integrate OpenCV into C++ Builder !

Hello

I also had this TLIB error while compiling cURL for C++ Builder using CMake

Error: the combinations '+*' or '*+' are not allowed

The reason was unexpected and trivial:
File objects1.rsp generated by CMake contains the list of obj files required by the linker. Unfortunately the paths to these files have folders separated by / (unix style), not \ (windows style). When I replaced all chars / by \ in this file, libcurl.lib linked correctly.
I hope it will help you compile your project.