Hi, I’m trying to use OpenCV with rust using the opencv-rust crate. Problem is I want to use the aruco lib so I have to manually build OpenCV with contrib. I keep running into linker errors and believe it’s because I’m not building all the needed files.
I got it to work using the prebuilt library files, so I’m wondering what build target is used to create those files?
For context, I’m using Windows.
berak
August 29, 2021, 5:27pm
2
correct. show your attempt, please
that’s some kind of “manual”, hand generated wrapper.
do you have a link for us ?
are you even sure, it covers the aruco module ?
looking here, see " Contrib modules" , it does not look like it’s in ;(
tl:dr:
it does not look like an opencv version problem at all, more like a deficiancy in the rust wrappers.
berak:
are you even sure, it covers the aruco module ?
looking here, see " Contrib modules, it does not look like it’s in ;(
That’s an older version of the OpenCV crate. The later versions have support. I don’t know too much about the binding generation process, but the bindings are generated automatically based on the built binaries. The crate automatically detects what modules are included and creates bindings for them.
I’ve tried a bunch of different ways of building OpenCV with cmake. I used the gui to configure it. Setting the OPENCV_EXTRAS_MODULE_PATH=C:/tools/opencv_contrib-4.5.3/modules
and reconfiguring. I also set BUILD_opencv_world=ON
. For the sake of compile time, I turned off Tests, Python, JS, and Java build cmake flags. In this case, I assume those would not mess up the files I need built.
Once I generate the VS 2017 project, I wasn’t sure what target to build. I’ve tried ALL_BUILD
, INSTALL
, ZERO_CHECK
, opencv_world
.
The linker error I get after building INSTALL
with these settings is:
opencv_linker_issue.txt
error: linking with `link.exe` failed: exit code: 1120
|
= note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\examples\\video_capture.video_capture.cdqdkw2l-cgu.0.rcgu.o" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\examples\\video_capture.video_capture.cdqdkw2l-cgu.1.rcgu.o" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\examples\\video_capture.video_capture.cdqdkw2l-cgu.2.rcgu.o" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\examples\\video_capture.video_capture.cdqdkw2l-cgu.3.rcgu.o" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\examples\\video_capture.video_capture.cdqdkw2l-cgu.4.rcgu.o" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\examples\\video_capture.video_capture.cdqdkw2l-cgu.5.rcgu.o" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\examples\\video_capture.video_capture.cdqdkw2l-cgu.6.rcgu.o" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\examples\\video_capture.video_capture.cdqdkw2l-cgu.7.rcgu.o" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\examples\\video_capture.video_capture.cdqdkw2l-cgu.8.rcgu.o" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\examples\\video_capture.video_capture.cdqdkw2l-cgu.9.rcgu.o" "/OUT:C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\examples\\video_capture.exe" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\examples\\video_capture.3xevgi0awe6yn5f6.rcgu.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis" "/LIBPATH:C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\deps" "/LIBPATH:C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\build\\opencv-6d18315bf2ff2fc0\\out" "/LIBPATH:C:\\tools\\opencv-4.5.3\\build\\install\\x64\\vc15\\lib"
"/LIBPATH:C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\deps\\libopencv-8579c76e595dcd51.rlib" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\deps\\liblibc-15196f83809c1a0d.rlib" "C:\\Users\\hpmas\\Documents\\Projects\\Misc\\opencv-rust\\target\\debug\\deps\\libnum_traits-e59e3836008bc571.rlib" "C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-7d8f1d3120dc2b31.rlib" "C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-00b4871c13b6f72d.rlib" "C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-38300272c9518b1b.rlib" "C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-008ea074760d3d54.rlib" "C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-5d102da67e495133.rlib" "C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-108ed3dcf248b873.rlib" "C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-bc9246c93f49e49a.rlib" "C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-7ca234fdcd728c26.rlib" "C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-e328514fb4ed0383.rlib" "C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-5d0a4c6a1ffa6373.rlib"
"C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-d379e9227cab087f.rlib" "C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-825774e96423c2c5.rlib" "C:\\Users\\hpmas\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-d5d1908505fa83bc.rlib" "opencv_world453.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
= note: libopencv-8579c76e595dcd51.rlib(img_hash.o) : error LNK2019: unresolved external symbol "public: void __cdecl cv::img_hash::ImgHashBase::compute(class cv::_InputArray const &,class cv::_OutputArray const &)" (?compute@ImgHashBase@img_hash@cv@@QEAAXAEBV_InputArray@3@AEBV_OutputArray@3@@Z) referenced in function cv_img_hash_ImgHashBase_compute_const__InputArrayR_const__OutputArrayR
libopencv-8579c76e595dcd51.rlib(img_hash.o) : error LNK2019: unresolved external symbol "public: double __cdecl cv::img_hash::ImgHashBase::compare(class cv::_InputArray const &,class cv::_InputArray const &)const " (?compare@ImgHashBase@img_hash@cv@@QEBANAEBV_InputArray@3@0@Z) referenced in function cv_img_hash_ImgHashBase_compare_const_const__InputArrayR_const__InputArrayR
libopencv-8579c76e595dcd51.rlib(img_hash.o) : error LNK2019: unresolved external symbol "public: static struct cv::Ptr<class cv::img_hash::AverageHash> __cdecl cv::img_hash::AverageHash::create(void)" (?create@AverageHash@img_hash@cv@@SA?AU?$Ptr@VAverageHash@img_hash@cv@@@3@XZ) referenced in function cv_img_hash_AverageHash_create
libopencv-8579c76e595dcd51.rlib(img_hash.o) : error LNK2019: unresolved external symbol "void __cdecl cv::img_hash::averageHash(class cv::_InputArray const &,class cv::_OutputArray const &)" (?averageHash@img_hash@cv@@YAXAEBV_InputArray@2@AEBV_OutputArray@2@@Z) referenced in function cv_img_hash_averageHash_const__InputArrayR_const__OutputArrayR
libopencv-8579c76e595dcd51.rlib(img_hash.o) : error LNK2019: unresolved external symbol "public: void __cdecl cv::img_hash::BlockMeanHash::setMode(int)" (?setMode@BlockMeanHash@img_hash@cv@@QEAAXH@Z) referenced in function cv_img_hash_BlockMeanHash_setMode_int
This file has been truncated. show original
berak
August 30, 2021, 6:42am
4
right, ok
that looks like a bad idea, as it seems to expect “single module” libs (but idk)
btw, did you build static or dyamic opencv libs ?
libopencv-8579c76e595dcd51.rlib(img_hash.o) : error LNK2019: unresolved external symbol "public: void __cdecl cv::img_hash::ImgHashBase::compute(class cv::_InputArray const &,class cv::_OutputArray const &)"
i guess, you get a ton more errors like this for the other opencv libs ?
img_hash.o
– this looks totally wrong. it should link against a .lib
file
. msvc also has .obj
files, while .o
is gcc
misconfigured toolchain ?
I seem to get the same error despite what libraries I’m using with the rust crate.
That img_hash.o
looks to be from the rust build, not the opencv build.
Looks like were correct, turning off BUILD_opencv_world generated the individual modules that do seem to work when build target INSTALL. I don’t know why opencv_world wouldn’t work since the opencv_world from Releases - OpenCV seems to work fine with opencv-rust examples. Do you know the build parameters/environment for that build? I would like to just link 1 file rather than list the individual modules.