最近工作的一个单片机项目项目,用了一款不知名的芯片,坑爹的开发商提供的编译器中有C++编译器,但是不能正常工作。好在我们的项目是纯C项目不需要C++编译器,只要在项目的cmake脚本中project命令指定为Cproject($NAME LANGUAGE C)
,这个坑就暂且绕过。
项目结构成型我打算将项目编译转为使用conan来管理。在安装项目的依赖库cjson的时候,出错了。
cjson/1.7.15: Copying sources to build folder
cjson/1.7.15: Building your package in C:\Users\guyadong\.conan\data\cjson\1.7.15\_\_\build\08753432bf90c0262ac35650be93af53440daf0b
cjson/1.7.15: Generator cmake created conanbuildinfo.cmake
cjson/1.7.15: Aggregating env generators
cjson/1.7.15: Calling build()
-- CAT1_SDK_PREFIX=E:/AL3XVXXX_SS_V2.2.4/MercuryLSDK
-- CAT1_SDK_PREFIX=E:/AL3XVXXX_SS_V2.2.4/MercuryLSDK
-- The C compiler identification is GNU 7.2.1
-- The CXX compiler identification is GNU 5.2.0
-- Check for working C compiler: E:/AL3XVXXX_SS_V2.2.4/MercuryLSDK/prebuilts/win32/gcc-arm-none-eabi/bin/arm-none-eabi-gcc.exe
-- Check for working C compiler: E:/AL3XVXXX_SS_V2.2.4/MercuryLSDK/prebuilts/win32/gcc-arm-none-eabi/bin/arm-none-eabi-gcc.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: P:/MinGW/mingw64/bin/g++.exe
-- Check for working CXX compiler: P:/MinGW/mingw64/bin/g++.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: called by CMake conan helper
-- Conan: called inside local cache
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Conan: Adjusting fPIC flag (ON)
-- Conan: Compiler GCC>=5, checking major version 7
-- Conan: Checking correct version: 5
CMake Error at conanbuildinfo.cmake:401 (message):
Detected a mismatch for the compiler version between your conan profile
settings and CMake:
Compiler version specified in your conan profile: 7
Compiler version detected in CMake: 5.2
Please check your conan profile settings (conan profile show
[default|your_profile_name])
P.S. You may set CONAN_DISABLE_CHECK_COMPILER CMake variable in order to
disable this check.
Call Stack (most recent call first):
conanbuildinfo.cmake:485 (conan_error_compiler_version)
conanbuildinfo.cmake:590 (check_compiler_version)
conanbuildinfo.cmake:140 (conan_check_compiler)
CMakeLists.txt:5 (conan_basic_setup)
出错误的原因很简单,
因为单片机的C++编译器不能用,所以我在conan profile文件中没有定义环境变量CXX,在cmake工具链文件中也没有定义CMAKE_CXX_COMPILER
指定C++编译器CMAKE_CXX_COMPILER
,
cmake自动在PATH搜索路径中找到了我的Windows平台的MinGW编译器,MinGW编译的版本与单片机编译器版本(profile中settings.compiler.version
)不一致,导致报错:
其实仔细看上面的错误提示也给出了解决方案,就是通过设置CONAN_DISABLE_CHECK_COMPILER
禁用编译器检查。这个值默认为false
,会检查找到的编译器版本是否与settings.compiler.version
匹配。
这里的CONAN_DISABLE_CHECK_COMPILER
不是环境变量是cmake变量,所以要将在cmake交叉编译工具链文件添加下面这一行就好了
SET(CONAN_DISABLE_CHECK_COMPILER true)