【问题标题】:Cross-compilation: error when trying to compile an OpenCV project for Windows交叉编译:尝试为 Windows 编译 OpenCV 项目时出错
【发布时间】:2015-11-10 13:58:58
【问题描述】:

我正在尝试使用 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编译器有问题但是我真的不明白如何解决它...

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

汤姆

*********编辑******* 亲爱的弗洛里安,

感谢您的帮助!

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

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

【问题讨论】:

  • 能把CMakeFiles/CMakeError.log的内容加进去吗?这就是 CMake 放置测试编译的命令行和错误的地方。另请参阅 CMake Wiki: CmakeMingw 以获取“官方”CMake MinGW 工具链示例。猜猜你的工具链看起来像是 32 位和 64 位的混合体。
  • here 是来自 Zygmunt Krynicki 的 mingw64 的工作示例。
  • 感谢您的回答!我已经尝试过您链接的工具链,但不幸的是它不起作用......我已经在我的第一篇文章中发布了输出。感谢您的帮助!
  • 但是根据您的日志文件,工具链确实有效。现在它说它找不到 CUDA:CUDA_TOOLKIT_ROOT_DIR not found or specified。所以我假设一个简单的测试程序可以工作。您的 CUDA 问题应该放入一个新问题中。我建议将set(CMAKE_FIND_DEBUG_MODE 1) 放在主要CMakeLists.txt 的顶部,并将输出添加到您的新问题中。顺便提一句。你确定 CUDA 可用于 MinGW 吗?参见例如Compiling c++ and cuda code with MinGW in QTCreator
  • 好的,非常感谢!因为比较着急,所以用VS编译了……不过我还是用MinGW再试一次吧!

标签: windows cmake cross-compiling


【解决方案1】:

正如@datenwolf 所说,CUDA 不适用于 MinGW。为了让 OpenCV 项目编译为 Windows,不幸的是,必须在普通 Windows 或虚拟机上使用 VS 编译它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-04
    • 2014-09-12
    • 2014-04-22
    • 2022-06-11
    • 1970-01-01
    • 2014-04-10
    • 2019-10-12
    相关资源
    最近更新 更多