CMake:C编译器无法编译简单的测试程序

Kag*_*sen 14 gcc mips cmake cross-compiling

我正在尝试针对Mips处理器交叉编译Azure IoT SDKC。使用较旧版本的CMake(2.8.12.2)交叉编译同一SDK的较旧版本是否可以正常工作,因此我怀疑它本身就是代码。我猜这是Mips GCC编译器。

错误信息:

CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "/usr/local/mipsisa32r2el/r23/bin/mipsisa32r2el-axis-linux-gnu-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/axis/azure-iot-sdk-c/cmake/iotsdk_linux/CMakeFiles/CMakeTmp

    Run Build Command:"/usr/bin/make" "cmTC_2cc84/fast"
    /usr/bin/make -f CMakeFiles/cmTC_2cc84.dir/build.make CMakeFiles/cmTC_2cc84.dir/build
    make[1]: Entering directory '/home/axis/azure-iot-sdk-c/cmake/iotsdk_linux/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_2cc84.dir/testCCompiler.c.o
    /usr/local/mipsisa32r2el/r23/bin/mipsisa32r2el-axis-linux-gnu-gcc --sysroot=/usr/local/mipsisa32r2el/r23    -o CMakeFiles/cmTC_2cc84.dir/testCCompiler.c.o   -c /home/axis/azure-iot-sdk-c/cmake/iotsdk_linux/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_2cc84
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_2cc84.dir/link.txt --verbose=1
    /usr/local/mipsisa32r2el/r23/bin/mipsisa32r2el-axis-linux-gnu-gcc --sysroot=/usr/local/mipsisa32r2el/r23      -rdynamic CMakeFiles/cmTC_2cc84.dir/testCCompiler.c.o  -o cmTC_2cc84 
    /usr/local/mipsisa32r2el/r23/lib/gcc/mipsisa32r2el-axis-linux-gnu/4.7.2/../../../../mipsisa32r2el-axis-linux-gnu/bin/ld: this linker was not configured to use sysroots
    collect2: error: ld returned 1 exit status
    CMakeFiles/cmTC_2cc84.dir/build.make:97: recipe for target 'cmTC_2cc84' failed
    make[1]: *** [cmTC_2cc84] Error 1
    make[1]: Leaving directory '/home/axis/azure-iot-sdk-c/cmake/iotsdk_linux/CMakeFiles/CMakeTmp'
    Makefile:126: recipe for target 'cmTC_2cc84/fast' failed
    make: *** [cmTC_2cc84/fast] Error 2
Run Code Online (Sandbox Code Playgroud)

不幸的是,我被Mips GCC编译器所困扰。有没有办法禁用此测试程序检查?

解决方案是将这些添加到工具链文件中:

SET (CMAKE_C_COMPILER_WORKS 1)
SET (CMAKE_CXX_COMPILER_WORKS 1)
Run Code Online (Sandbox Code Playgroud)

Kam*_*Cuk 14

cmake尝试使用“标准”(按照cmake认为是标准的)编译器选项编译可执行文件,并尝试运行该可执行文件,以查看编译器是否正常工作。可执行文件很简单,通常像int main(int argc) { return argc - 1; }

交叉编译时不能这样做。因为通常你不能链接适当的标准C库,你没有printf,或_start_exit或类似,参数传递给main被执行定义,或者你需要一个链接脚本或者您不能运行在主机上的交叉编译的源,等等...简单:您通常不能在主机上运行交叉编译的可执行文件,并且在大多数情况下,即使编译起来也很难做到。

常见的解决方案是在以下位置设置project()

set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
Run Code Online (Sandbox Code Playgroud)

这样,cmake将尝试在此处编译静态库而不是可执行文件。这样可以避免运行链接器,并打算进行交叉编译。

您可以设置CMAKE_C_COMPILER_WORKS,它会在这里省略检查,但是我认为这CMAKE_TRY_COMPILE_TARGET_TYPE是更合适的解决方案。


gan*_*opp 6

重新编译项目时遇到了同样的问题。结果发现编译器同时也更新了。

删除build目录并重新创建后,编译完成,没有错误。