1

I'm trying to cross-compile SFML from Linux to Windows for a project of mine. Prebuilt SFML packages are not an option.

So, I installed the mingw-w64 package,and set up a toolchain file, and went ahead trying to compile SFML from source using CMake, only to find that the GCC compiler provided is broken.

Full error message:

CMake Error at /usr/share/cmake-3.5/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/chemicalchems/SFML-2.3.2/build/CMakeFiles/CMakeTmp



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

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

  make[1]: Entering directory
  '/home/chemicalchems/SFML-2.3.2/build/CMakeFiles/CMakeTmp'

  Building C object CMakeFiles/cmTC_9b6e7.dir/testCCompiler.c.o

  /usr/bin/i686-w64-mingw32-gcc -o
  CMakeFiles/cmTC_9b6e7.dir/testCCompiler.c.o -c
  /home/chemicalchems/SFML-2.3.2/build/CMakeFiles/CMakeTmp/testCCompiler.c

  Linking C executable cmTC_9b6e7

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

  /usr/bin/i686-w64-mingw32-gcc CMakeFiles/cmTC_9b6e7.dir/testCCompiler.c.o
  -o cmTC_9b6e7 -rdynamic

  i686-w64-mingw32-gcc: error: unrecognized command line option
  ‘-rdynamic’

  CMakeFiles/cmTC_9b6e7.dir/build.make:97: recipe for target 'cmTC_9b6e7'
  failed

  make[1]: *** [cmTC_9b6e7] Error 1

  make[1]: Leaving directory
  '/home/chemicalchems/SFML-2.3.2/build/CMakeFiles/CMakeTmp'

  Makefile:126: recipe for target 'cmTC_9b6e7/fast' failed

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

So the problem is that i686-w64-mingw32-gcc doesn't accept the -rdynamic option. I've tried telling CMake that it should not test the C compiler in my toolchain file but it keeps on checking it and thus failing.

Toolchain file:

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR i686)
set(CMAKE_CROSSCOMPILING 1)

set(CMAKE_C_COMPILER_WORKS 1)

set(TOOLCHAIN_PREFIX i686-w64-mingw32)

# cross compilers to use for C and C++
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

# target environment on the build host system
#   set 1st to dir with the cross compiler's C/C++ headers/libs
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands to
# search for headers/libs in the target environment and
# search for programs in the build 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)

Any help would be very much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.