opencv-rust icon indicating copy to clipboard operation
opencv-rust copied to clipboard

Linking error on Windows 10

Open usamazf opened this issue 3 years ago • 1 comments

Hello, I am trying to use OpenCV compiled from source. I already have the OpenCV built manually working for me both in C++ and Python. But when using in rust I get linking errors. I have setup all required environment variables and have no idea why this issue is arising. Information needed for are as follows:

  1. Windows 10
  2. The way you installed OpenCV: Compiled latest version from source with contrib and GPU support
  3. OpenCV version = 4.6.0
  4. rustc version (rustc --version) = "rustc 1.63.0 (4b91a6ea7 2022-08-08)"
  5. Attach the full output of the following command from your project directory: linking_error.txt

usamazf avatar Aug 22 '22 07:08 usamazf

Sounds like img_hash module is not built in the opencv_world460.dll, but is present in the headers in E:\Libraries\C++\opencv_gpu\opencv_build\install\include. Are the headers matching with the library being used? As a workaround you can try disable the img_hash feature if you're not using it so that this module is not build.

twistedfall avatar Aug 23 '22 07:08 twistedfall

I faced the same linking issue. I compiled opencv with contrib with visual c++ 2022. LLVM ver 14 opencv 4.6 i disabled img_hash feature but the linking still generated the same errors. link_error.txt

yeokiwi avatar Oct 01 '22 07:10 yeokiwi

Can you please post the full output of cargo build -vv after doing a cargo clean?

twistedfall avatar Oct 01 '22 07:10 twistedfall

Found the problem. img_hash was not built into opencv_world460.lib. It was built separately as opencv_img_hash460.lib. Therefore, to link properly, we had to add opencv_img_hash460.lib to OPENCV_LINK_LIBS.

OPENCV_LINK_LIBS = opencv_world460,opencv_img_hash460

the bindings worked fine after i included the img_hash lib.

yeokiwi avatar Oct 01 '22 08:10 yeokiwi

Great find! I'll update the troubleshooting guide

twistedfall avatar Oct 01 '22 10:10 twistedfall