交叉编译:尝试编译Windows的OpenCV项目时出错

时间:2015-11-10 13:58:58

标签: windows cmake cross-compiling

我正在尝试使用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会返回以下错误:

-- 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编译器存在问题,但我真的不明白如何解决它......

如果您有任何想法,请提前感谢您!

汤姆

********* EDIT ******* 亲爱的弗洛里安,

感谢您的帮助!

我尝试使用您链接的工具链,但我收到以下错误:

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时运行良好...

1 个答案:

答案 0 :(得分:0)

正如@datenwolf所说,CUDA与MinGW不兼容。为了获得用于Windows的OpenCV项目编译,不幸的是,必须在普通Windows或虚拟机上使用VS对其进行编译。