交叉编译:尝试为 Windows 编译 OpenCV 项目时出错
Cross-compilation: error when trying to compile an OpenCV project for Windows
我正在尝试使用 cmake 从我的 GNU/Linux 机器(64 位,Debian Jessie)为 Windows 编译一个 C++/OpenCV 项目。
我的编译器是 mingw,因此我使用以下工具链启动 cmake:
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
# which compilers to use for C and C++
SET(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
SET(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
SET(CMAKE_RC_COMPILER i586-mingw32-windres)
SET(CUDA_TOOLKIT_ROOT_DIR /usr/bin/nvcc)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /usr/i686-mingw32)
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
但是cmake return出现如下错误:
-- The C compiler identification is GNU 4.9.1
-- The CXX compiler identification is GNU 4.9.1
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc -- broken
CMake Error at /usr/share/cmake-3.0/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "/usr/bin/x86_64-w64-mingw32-gcc" is not able to compile a
simple test program.
It fails with the following output:
Change Dir: /data/These/1_A/programmes/remanence/online_version_win32/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTryCompileExec3184109505/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec3184109505.dir/build.make
CMakeFiles/cmTryCompileExec3184109505.dir/build
make[1]: Entering directory
'/data/These/1_A/programmes/remanence/online_version_win32/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report
/data/These/1_A/programmes/remanence/online_version_win32/CMakeFiles/CMakeTmp/CMakeFiles
1
Building C object
CMakeFiles/cmTryCompileExec3184109505.dir/testCCompiler.c.o
/usr/bin/x86_64-w64-mingw32-gcc -o
CMakeFiles/cmTryCompileExec3184109505.dir/testCCompiler.c.o -c
/data/These/1_A/programmes/remanence/online_version_win32/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTryCompileExec3184109505
/usr/bin/cmake -E cmake_link_script
CMakeFiles/cmTryCompileExec3184109505.dir/link.txt --verbose=1
/usr/bin/x86_64-w64-mingw32-gcc
CMakeFiles/cmTryCompileExec3184109505.dir/testCCompiler.c.o -o
cmTryCompileExec3184109505 -rdynamic
x86_64-w64-mingw32-gcc: erreur: unrecognized command line option
‘-rdynamic’
CMakeFiles/cmTryCompileExec3184109505.dir/build.make:88: recipe for target
'cmTryCompileExec3184109505' failed
make[1]: Leaving directory
'/data/These/1_A/programmes/remanence/online_version_win32/CMakeFiles/CMakeTmp'
make[1]: *** [cmTryCompileExec3184109505] Error 1
Makefile:118: recipe for target 'cmTryCompileExec3184109505/fast' failed
make: *** [cmTryCompileExec3184109505/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
但是我不明白为什么...好像是C编译器有问题但是我真的不明白怎么解决...
如果您有任何想法,请提前致谢!
汤姆
*********编辑*******
亲爱的弗洛里安,
感谢您的帮助!
我尝试使用您链接的工具链,但出现以下错误:
CUDA_TOOLKIT_ROOT_DIR not found or specified
CMake Error at /usr/share/cmake-3.0/Modules/FindCUDA.cmake:605 (if):
if given arguments:
"CUDA_VERSION" "VERSION_GREATER" "5.0" "AND" "CMAKE_CROSSCOMPILING" "AND" "MATCHES" "arm" "AND" "EXISTS" "CUDA_TOOLKIT_ROOT_DIR-NOTFOUND/targets/armv7-linux-gnueabihf"
Unknown arguments specified
Call Stack (most recent call first):
CMakeLists.txt:4 (find_package)
-- Configuring incomplete, errors occurred!
和here CMakeOutput.log
似乎 CMake 没有找到正确的 CUDA,但我不明白为什么,因为它在我为 GNU/Linux...
编译时运行良好
正如@datenwolf 所说,CUDA 不适用于 MinGW。不幸的是,为了获得针对 windows 编译的 OpenCV 项目,必须在普通 Windows 或虚拟机上使用 VS 对其进行编译。
我正在尝试使用 cmake 从我的 GNU/Linux 机器(64 位,Debian Jessie)为 Windows 编译一个 C++/OpenCV 项目。 我的编译器是 mingw,因此我使用以下工具链启动 cmake:
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
# which compilers to use for C and C++
SET(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
SET(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
SET(CMAKE_RC_COMPILER i586-mingw32-windres)
SET(CUDA_TOOLKIT_ROOT_DIR /usr/bin/nvcc)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /usr/i686-mingw32)
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
但是cmake return出现如下错误:
-- The C compiler identification is GNU 4.9.1
-- The CXX compiler identification is GNU 4.9.1
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc -- broken
CMake Error at /usr/share/cmake-3.0/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "/usr/bin/x86_64-w64-mingw32-gcc" is not able to compile a
simple test program.
It fails with the following output:
Change Dir: /data/These/1_A/programmes/remanence/online_version_win32/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTryCompileExec3184109505/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec3184109505.dir/build.make
CMakeFiles/cmTryCompileExec3184109505.dir/build
make[1]: Entering directory
'/data/These/1_A/programmes/remanence/online_version_win32/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report
/data/These/1_A/programmes/remanence/online_version_win32/CMakeFiles/CMakeTmp/CMakeFiles
1
Building C object
CMakeFiles/cmTryCompileExec3184109505.dir/testCCompiler.c.o
/usr/bin/x86_64-w64-mingw32-gcc -o
CMakeFiles/cmTryCompileExec3184109505.dir/testCCompiler.c.o -c
/data/These/1_A/programmes/remanence/online_version_win32/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTryCompileExec3184109505
/usr/bin/cmake -E cmake_link_script
CMakeFiles/cmTryCompileExec3184109505.dir/link.txt --verbose=1
/usr/bin/x86_64-w64-mingw32-gcc
CMakeFiles/cmTryCompileExec3184109505.dir/testCCompiler.c.o -o
cmTryCompileExec3184109505 -rdynamic
x86_64-w64-mingw32-gcc: erreur: unrecognized command line option
‘-rdynamic’
CMakeFiles/cmTryCompileExec3184109505.dir/build.make:88: recipe for target
'cmTryCompileExec3184109505' failed
make[1]: Leaving directory
'/data/These/1_A/programmes/remanence/online_version_win32/CMakeFiles/CMakeTmp'
make[1]: *** [cmTryCompileExec3184109505] Error 1
Makefile:118: recipe for target 'cmTryCompileExec3184109505/fast' failed
make: *** [cmTryCompileExec3184109505/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
但是我不明白为什么...好像是C编译器有问题但是我真的不明白怎么解决...
如果您有任何想法,请提前致谢!
汤姆
*********编辑******* 亲爱的弗洛里安,
感谢您的帮助!
我尝试使用您链接的工具链,但出现以下错误:
CUDA_TOOLKIT_ROOT_DIR not found or specified
CMake Error at /usr/share/cmake-3.0/Modules/FindCUDA.cmake:605 (if):
if given arguments:
"CUDA_VERSION" "VERSION_GREATER" "5.0" "AND" "CMAKE_CROSSCOMPILING" "AND" "MATCHES" "arm" "AND" "EXISTS" "CUDA_TOOLKIT_ROOT_DIR-NOTFOUND/targets/armv7-linux-gnueabihf"
Unknown arguments specified
Call Stack (most recent call first):
CMakeLists.txt:4 (find_package)
-- Configuring incomplete, errors occurred!
和here CMakeOutput.log
似乎 CMake 没有找到正确的 CUDA,但我不明白为什么,因为它在我为 GNU/Linux...
编译时运行良好正如@datenwolf 所说,CUDA 不适用于 MinGW。不幸的是,为了获得针对 windows 编译的 OpenCV 项目,必须在普通 Windows 或虚拟机上使用 VS 对其进行编译。