-
-
Notifications
You must be signed in to change notification settings - Fork 173
Description
Hello, I'am cross-compiling OpenCV to Android on Windows and using OpenCV_DIR
to do it by CMake. But I got this error:
[opencv 0.95.1] === cmake find-package link probe command: "cmake" "-S" "xxx\\opencv-0.95.1\\cmake" "-DOCVRS_PACKAGE_NAME=OpenCV" "-DCMAKE_BUILD_TYPE=Debug" "--find-package" "-DCOMPILER_ID=GNU" "-DLANGUAGE=CXX" "-DMODE=LINK" "-DNAME=OpenCV"
...
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: ld.lld: error: unable to find library -lkernel32␍
ld.lld: error: unable to find library -luser32␍
ld.lld: error: unable to find library -lgdi32␍
ld.lld: error: unable to find library -lwinspool␍
ld.lld: error: unable to find library -lshell32␍
ld.lld: error: unable to find library -lole32␍
ld.lld: error: unable to find library -loleaut32␍
ld.lld: error: unable to find library -luuid␍
ld.lld: error: unable to find library -lcomdlg32␍
ld.lld: error: unable to find library -ladvapi32␍
clang: error: linker command failed with exit code 1 (use -v to see invocation)␍
␍
I found the reason lies here. It doesn't provide any toolchain so CMake --find-package
ouputs linker arguments binding Windows libraries, which are unavailable on Android.
Lines 616 to 629 in 5ee7bc6
fn run_probe( | |
&self, | |
include_paths: Option<EnvList>, | |
link_paths: Option<EnvList>, | |
link_libs: Option<EnvList>, | |
) -> Result<Library> { | |
match self { | |
Probe::Environment => Library::probe_from_paths(include_paths, link_paths, link_libs), | |
Probe::PkgConfig => Library::probe_pkg_config(include_paths, link_paths, link_libs), | |
Probe::CMake => Library::probe_cmake(include_paths, link_paths, link_libs, None, None, None), | |
Probe::VcpkgCMake => Library::probe_vcpkg_cmake(include_paths, link_paths, link_libs), | |
Probe::Vcpkg => Library::probe_vcpkg(include_paths, link_paths, link_libs), | |
} | |
} |
I tried Android NDK CMake Toolchain -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake
and added -DOpenCV_DIR=path/to/opencv
after finding that OpenCV_DIR
environment variable is not working when setting toolchain (using cmake -LA xxx
can check which variables are working). Finally I succeed to cross-compile it.
So could you please provide environment variables like OPENCV_CMAKE_TOOLCHAIN_FILE
and OPENCV_CMAKE_ARGS
, so we can pass arguments to CMake to make cross-compilation successful?