Q&A The C compiler “C:/xxx/bin/gcc.exe“ is not able to compile a simple test Program.

环境

Win10(64位)、Qt6.30、CMake、AiThinkerIDE_V1.5.2

执行

QT中打开一个CMake项目然后构建,点击 构建》执行CMake

​​​​​​​ 

CMake构建出错,如下所示

C:\Qt.pureC\Tools\CMake_64\share\cmake-3.21\Modules\CMakeTestCCompiler.cmake:69: error: The C compiler "C:/Qt.pureC/Tools/mingw810_32/bin/gcc.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: C:/Users/qzm/Documents/ws2022/School/Course.IotGateway.2022/ws/build-prj_QtPureCFirework.V0.1-MinGW8_1_0_32_bit_for_C-Debug/CMakeFiles/CMakeTmp Run Build Command(s):C:/Qt.pureC/Tools/Ninja/ninja.exe cmTC_5a38b && [1/2] Building C object CMakeFiles\cmTC_5a38b.dir\testCCompiler.c.obj FAILED: CMakeFiles/cmTC_5a38b.dir/testCCompiler.c.obj C:\Qt.pureC\Tools\mingw810_32\bin\gcc.exe -o CMakeFiles\cmTC_5a38b.dir\testCCompiler.c.obj -c C:\Users\qzm\Documents\ws2022\School\Course.IotGateway.2022\ws\build-prj_QtPureCFirework.V0.1-MinGW8_1_0_32_bit_for_C-Debug\CMakeFiles\CMakeTmp\testCCompiler.c ninja: build stopped: subcommand failed.

问题分析

    只要通过CMake编译C或C++代码,不管是在Windows、Linux、Mac上还是进行交叉编译,配置不当时,就有可能出现” is not able to compile a simple test program”问题。

    CMake在编译你的C或C++代码前,会先验证你指定的编译器是否可以正常工作。CMake会先自动生成一个非常简单的testCCompiler.c或testCXXCompiler.cxx文件,它会尝试使用CMake认为的”standard”编译器选项来编译此文件,若是非交叉编译,可能还会尝试执行该可执行文件,以查看编译器是否正常工作

” is not able to compile a simple test program”问题的可能原因:

(1).Linux上有多个gcc/g++版本,编译时未按你预期的gcc/g++版本进行编译;

(2).Linux版本低;

(3).系统找不到指定的文件,如动态库。

    由于开发环境安装了多个版本的QT、和AiThinkerIDE_V1.5.2,这些环境都含有mingw工具链,在某个工具链嵌套调用时,由于环境变量path有优先级,很有可能调用到其他的工具链的工具,产生意想不到的错误

解决办法

STEP1:按下图修改系统变量中的path环境变量,

图中的(1)我是放到最高优先级,是否必须这样做,没有进一步确认。

图中的(2)是AiThinkerIDE,这个IDE在环境变量中是最容易和QT的mingw工具链产生Mingw版本冲突。

 STEP2:改好环境变量后,关闭“环境变量”,重启QT,再执行CMake,问题解决。 

STEP3:为了确认AiThinkerIDE是否能和Qt的Mingw工具链共存,进行AiThinkerIDE,重新构建了一些,PASS。但要注意的是,AiThinkerIDE加载的PRJ是ESP8266 SDK的2.1版本,用到的工具链是Cygwin,所以,如果要编译3.0以上的SDK时,才会用到Mingw工具链,这个没有测试。但从path环境变量中初步判断,按上图的环境变量设置,QT使用CMake+Mingw工具链,是能和AiThinkerIDE共存的

猜你喜欢

转载自blog.csdn.net/u012915636/article/details/124428831