Closed amedeedaboville closed 4 years ago
Thank you for such a thorough investigation! It sounds like you’re onto something there. I will be able l check it in more detail some time tomorrow. For now you might want to try the clang
branch. It has a completely rewritten binding generator, and it uses libclang instead of python script. And it only exports symbols marked as such (with some exceptions). So you'll need to have llvm/clang installed and maybe manually point clang_sys crate to it. I haven’t been able to make on work on windows yet, but you might have more luck.
Wow, amazing, thanks a lot! That binding generator looks like quite a piece work! Thanks for doing this complex task of binding opencv to Rust.
Hi, thanks a lot for opencv-rust. It's made me able to use opencv in rust, and on windows no less.
I'm on windows, (
nightly-x86_64-pc-windows-msvc
), using thecontrib
feature along withbuildtime-bindgen
for aruco marker detection. I've installed opencv with vcpkg, and have installed the[contrib]
sub-package there.Non-contrib features work fine. But using a contrib feature (
aruco
), when I compile my example on windows (even in release mode) I getand a number of other missing symbols (some of them are
cv::face::FacemarkLBF::BBox::BBox
, which were mentioned in issue #75, but I believe are part of a bigger issue detailled here)I think what's happening is that these symbols are not meant to be exported(at least on windows). On windows, symbols are not exported by default, and one needs to add
__declspec(dllexport)
to ones functions for them to be exported.Apparently, this is what the CV_EXPORTS_W macro does:
Now, for the aruco wrapper,
aruco.hpp
contains:And the second function is not CV_EXPORTS_W.
The same thing is happening in the
face
module, where if we look at https://github.com/opencv/opencv_contrib/blob/master/modules/face/include/opencv2/face/facemarkLBF.hpp#L96 theBBox
class is not exported.I read issue #75, and OP there seems to have resolved it by installing precompiled binary files, which is curious as to why the symbols are exported there. I'm wondering if they were cross compiled with gcc? You mentioned in that issue that the symbols are there on linux, but there is a platform difference here where they aren't there on windows by default.
I'm trying to work around this by having
vcpkg
use theCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
flag, which is discouraged, but I haven't filtered the flag down in the right place yet.Does this make sense or do you think I am wrong somewhere? I think in the future, things like https://github.com/twistedfall/opencv-rust/blob/af4759f937865473acb7fac870a09ea710f440b3/src/opencv/hub/aruco.rs#L92 shouldn't use non EXPORT_W symbols.
For now, a workaround (I'm not familiar with opencv-rust enough yet to know if this is possible) could be to only link to these functions on non-windows with
#[cfg!(not(target_os = "windows"))]
Thanks.