MantisBT - CMake
View Issue Details
0013855CMakeModulespublic2013-01-17 17:392013-06-03 09:05
Andres Gomez 
 
highmajoralways
closedno change required 
Linux x86_64Ubuntu12.10
CMake 2.8.9 
 
0013855: Cross compilation with MinGW fails on initial GCC compilation test because mingw doesn't support the -rdynamic linking flag
When configuring a simple program with CMake support it fails because CMake is not able to find a C compiler capable of compiling a simple test program.

The error happens because, as we try to crosscompile, the C compiler program found is MinGW (/usr/bin/i686-w64-mingw32-gcc), which doesn't support the Linking "-rdynamic" flag.
$ cmake .
debug trycompile on
-- The C compiler identification is GNU 4.6.3
-- Check for working C compiler: /usr/bin/i686-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/i686-w64-mingw32-gcc -- broken
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "/usr/bin/i686-w64-mingw32-gcc" is not able to compile a
  simple test program.

  It fails with the following output:

   Change Dir: /home/tanty/swftools-jhbuild.git/checkout.dbg/openjpeg-2.0.0/CMakeFiles/CMakeTmp



  Run Build Command:/usr/bin/make "cmTryCompileExec4018385851/fast"

  /usr/bin/make -f CMakeFiles/cmTryCompileExec4018385851.dir/build.make
  CMakeFiles/cmTryCompileExec4018385851.dir/build

  make[1]: Entering directory
  `/home/tanty/swftools-jhbuild.git/checkout.dbg/openjpeg-2.0.0/CMakeFiles/CMakeTmp'


  /usr/bin/cmake -E cmake_progress_report
  /home/tanty/swftools-jhbuild.git/checkout.dbg/openjpeg-2.0.0/CMakeFiles/CMakeTmp/CMakeFiles
  1

  Building C object










  CMakeFiles/cmTryCompileExec4018385851.dir/testCCompiler.c.o

  /usr/bin/i686-w64-mingw32-gcc -mms-bitfields -march=i686
  -I/home/tanty/swftools-jhbuild.git/mingw-target.dbg//include -D_WIN32=1
  -D__USE_MINGW_ANSIO_STDIO=1 -DWIN32=1 -DOPJ_STATIC=1 -g -O0 -o
  CMakeFiles/cmTryCompileExec4018385851.dir/testCCompiler.c.o -c


  /home/tanty/swftools-jhbuild.git/checkout.dbg/openjpeg-2.0.0/CMakeFiles/CMakeTmp/testCCompiler.c


  Linking C executable cmTryCompileExec4018385851

  /usr/bin/cmake -E cmake_link_script
  CMakeFiles/cmTryCompileExec4018385851.dir/link.txt --verbose=1

  /usr/bin/i686-w64-mingw32-gcc -mms-bitfields -march=i686
  -I/home/tanty/swftools-jhbuild.git/mingw-target.dbg//include -D_WIN32=1
  -D__USE_MINGW_ANSIO_STDIO=1 -DWIN32=1 -DOPJ_STATIC=1 -g -O0
  -L/home/tanty/swftools-jhbuild.git/mingw-target.dbg/lib64
  -L/home/tanty/swftools-jhbuild.git/mingw-target.dbg//lib -static
  CMakeFiles/cmTryCompileExec4018385851.dir/testCCompiler.c.o -o
  cmTryCompileExec4018385851 -rdynamic

  i686-w64-mingw32-gcc: error: unrecognized option '-rdynamic'

  make[1]: *** [cmTryCompileExec4018385851] Error 1

  make[1]: Leaving directory
  `/home/tanty/swftools-jhbuild.git/checkout.dbg/openjpeg-2.0.0/CMakeFiles/CMakeTmp'


  make: *** [cmTryCompileExec4018385851/fast] Error 2





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:24 (project)


-- Configuring incomplete, errors occurred!
No tags attached.
patch No--rdynamic-flag-for-MINGW.patch (678) 2013-01-17 17:43
https://public.kitware.com/Bug/file/4616/No--rdynamic-flag-for-MINGW.patch
Issue History
2013-01-17 17:39Andres GomezNew Issue
2013-01-17 17:43Andres GomezNote Added: 0032115
2013-01-17 17:43Andres GomezFile Added: No--rdynamic-flag-for-MINGW.patch
2013-01-18 09:13Brad KingNote Added: 0032120
2013-01-18 12:25Andres GomezNote Added: 0032123
2013-01-18 13:18Brad KingStatusnew => resolved
2013-01-18 13:18Brad KingResolutionopen => no change required
2013-06-03 09:05Robert MaynardNote Added: 0033188
2013-06-03 09:05Robert MaynardStatusresolved => closed

Notes
(0032115)
Andres Gomez   
2013-01-17 17:43   
The problem seems to be the CMAKE_SHARED_LIBRARY_LINK_C_FLAGS macro which is set to "-rdynamic" in the Modules/Platform/Linux-GNU.cmake file.

This patch sets that linking flag conditionally to the presence of MINGW.
(0032120)
Brad King   
2013-01-18 09:13   
The problem is that Linux-GNU is getting loaded when cross-compiling for Windows. When cross compiling the toolchain file should set CMAKE_SYSTEM_NAME to Windows so that Linux platform information is not loaded.
(0032123)
Andres Gomez   
2013-01-18 12:25   
You are right, the problem is not using the proper toolchain file as described in:
http://www.cmake.org/Wiki/CmakeMingw [^]

This report is invalid, although it is interesting that CMake is not that helpful to make the developer aware about the need of this toolchain file.
(0033188)
Robert Maynard   
2013-06-03 09:05   
Closing resolved issues that have not been updated in more than 4 months.