[CMake] Can't build something with MinGW

Mathieu Bridon bochecha at daitauha.fr
Fri Sep 25 04:41:19 EDT 2015


Hi everyone,

I've been trying to build something for Windows on Fedora with MinGW
and I'm hitting a road block.

First, the problem: CMake fails trying to test the C++ compiler with
the following error message:

  Linking CXX executable cmTC_f5bba

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

  /usr/bin/i686-w64-mingw32-g++ -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2
  -fexceptions --param=ssp-buffer-size=4
  CMakeFiles/cmTC_f5bba.dir/testCXXCompiler.cxx.o -o cmTC_f5bba -rdynamic

  i686-w64-mingw32-g++: error: unrecognized command line option '-rdynamic'

The -rdynamic flag is indeed not supported with MinGW, so CMake
shouldn't pass it.

I'm using Fedora's mingw32-cmake command which passes this toolchain
file to CMake:

http://pkgs.fedoraproject.org/cgit/mingw-filesystem.git/tree/toolchain-
mingw32.cmake?h=f22

As you can see, it sets CMAKE_SYSTEM_NAME to Windows.

After a few hours of trying to figuring this out, and adding
MESSAGE(...) lines everywhere in the /usr/share/cmake files involved in
building the project, I added the following line to the top of the
/usr/share/cmake/Modules/CMakeCXXInformation.cmake file:

  MESSAGE("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")

I'm attaching the full output of the build to this email. In it, you
will see that for most of the build, the CMAKE_SYSTEM_NAME variable is
correctly set to "Windows", until a point where it is set to "Linux".

As a result, the /usr/share/cmake/Modules/Platform/Linux-GNU.cmake file
gets loaded, which contains this line:

  set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-rdynamic")

And this is exactly what causes my build to fail.

So I guess something is wrong here. I don't know much CMake, but I find
it surprising that the CMAKE_SYSTEM_NAME variable would change like
this in the middle of the build process.

What am I doing wrong? :)

Thanks,


-- 
Mathieu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: build.log
Type: text/x-log
Size: 3755 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150925/a809da6a/attachment-0001.bin>


More information about the CMake mailing list