![mingw-64 GCC 在 Ubuntu 下无法使用](https://linux22.com/image/1056698/mingw-64%20GCC%20%E5%9C%A8%20Ubuntu%20%E4%B8%8B%E6%97%A0%E6%B3%95%E4%BD%BF%E7%94%A8.png)
我正在尝试将 SFML 从 Linux 交叉编译到 Windows,用于我的一个项目。预构建的 SFML 包不是一个选项。
因此,我安装了 mingw-w64 包,并设置了一个工具链文件,然后尝试使用 CMake 从源代码编译 SFML,结果发现提供的 GCC 编译器已损坏。
完整错误信息:
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
所以问题是 i686-w64-mingw32-gcc 不接受该-rdynamic
选项。我尝试告诉 CMake 它不应该在我的工具链文件中测试 C 编译器,但它继续检查它,因此失败。
工具链文件:
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)
任何帮助都将非常感激。
答案1
有趣的是,我在 Ubuntu 20.04 中遇到了完全相同的问题,也想编译 SFML。
实际上,您几乎已经知道了CMAKE_C_COMPILER_WORKS
。但是正确的选项是CMAKE_CXX_COMPILER_WORKS