1

I am trying to compile a C++/OpenCV project for Windows from my GNU/Linux machine (64 bits, Debian Jessie), using cmake. My compiler is mingw, thus I am launching cmake with the following toolchain:

# 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)

But cmake return the following error:

-- 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!

But I do not understand why... It seems that there is a problem with the C compiler but I really do not understand how to solve it...

Thank you very much in advance if you have any idea!

Tom

*********EDIT******* Dear Florian,

Thank you for your help!

I tried to use the toolchain you linked but I get the following error:

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!

And here the CMakeOutput.log

It seems that CMake does not find properly CUDA, but I do not understand why because it works well when I am compiling for GNU/Linux...

Tom
  • 303
  • 3
  • 14
  • Could you please add the content of `CMakeFiles/CMakeError.log`? That's where CMake puts the test compile's command line and the error. See also [CMake Wiki: CmakeMingw](http://www.vtk.org/Wiki/CmakeMingw) for an "official" CMake MinGW toolchain example. Just one guess your toolchain looks like a mixture of 32bit and 64bit. – Florian Nov 13 '15 at 08:09
  • And [here](https://github.com/zyga/cmake-toolchains/blob/master/Toolchain-Ubuntu-mingw64.cmake) is a working example for `mingw64` from Zygmunt Krynicki. – Florian Nov 13 '15 at 08:21
  • Thanks, for your answer! I've tried the toolchain you linked but unfortunately it does not work... I have posted the outputs in my first post. Thank you for your help! – Tom Nov 16 '15 at 12:45
  • But according to your log file the toolchain did work. Now it's saying that it can't find CUDA: `CUDA_TOOLKIT_ROOT_DIR not found or specified`. So I assume that a simple test program would work. Your CUDA problem should be put into a new question. I would recommend to put `set(CMAKE_FIND_DEBUG_MODE 1)` at the top of your main `CMakeLists.txt` and add the output to your new question. Btw. are you sure CUDA is available for MinGW? See e.g. [Compiling c++ and cuda code with MinGW in QTCreator](http://stackoverflow.com/questions/22909341/compiling-c-and-cuda-code-with-mingw-in-qtcreator) – Florian Nov 16 '15 at 20:18
  • Ok, thank you very much! As I was quite in a hurry, I compiled it using VS... But I will try again with MinGW! – Tom Nov 24 '15 at 08:54
  • @TomCombriat: CUDA does not work with MinGW. When compiling for a Windows target nvcc (the CUDA compiler) looks for a Visual Studio environment. Requests for making the CUDA toolkit work with MinGW have been ignored by NVidia to this date. – datenwolf Apr 16 '16 at 14:42

1 Answers1

0

As said by @datenwolf, CUDA does not work with MinGW. In order to get an OpenCV project compiling for windows, one unfortunately has to compile it with VS, on a plain Windows or a virtual machine.

Tom
  • 303
  • 3
  • 14