更新时间:2023-11-10 19:43:52
我的问题通过 回复 我的错误报告,但我在此处添加了答案,以便将所有信息集中在一处以供将来参考.
My question was answered through the reply to my bug report, but I add the answer here to have all information in one place for future reference.
简而言之:如果您从 llvm.org.如果您想使用 clang/clang++ 接口(这是为 ARM 交叉编译所必需的),您必须通过 msys2 安装 Clang.
In short: CMake currently does not support to use the clang/clang++ command line interface if you install Clang from llvm.org. If you want to use the clang/clang++ interface (which is necessary to cross-compile for ARM) you have to install Clang via msys2.
详细
Windows 上的 Clang 有两个不同的命令行界面:
Clang on Windows has two different command line interfaces:
为了对 ARM 进行交叉编译,您需要 clang/clang++ 接口.问题是 CMake 支持不同的接口,具体取决于您安装 Clang 的方式(请参阅 bug在 CMake 问题跟踪器中了解更多详细信息):
In order to cross-compile for ARM you need the clang/clang++ interface. The Problem is CMake supports different interfaces depending on how you installed Clang (see the bug in the CMake issue tracker for more details):
这就是我所做的:
工具链文件
我的原始工具链文件有两个问题花了我很长时间才修复.所以我希望这会为其他人节省一些时间:
There were two problems with my original toolchain file that took my a long time to fix. So I hope this will save others some time:
这是我使用的最终工具链文件(您还可以在此GitHub 存储库):
Here is the final toolchain file I used (you can also find a good example for a toolchain file in this GitHub repo):
cmake_minimum_required(VERSION 3.13)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)
if(DEFINED ENV{GCC_ARM_TOOLCHAIN})
set(GCC_ARM_TOOLCHAIN $ENV{GCC_ARM_TOOLCHAIN})
else()
set(GCC_ARM_TOOLCHAIN "C:/Users/user/tools/gcc-arm-none-eabi-7-2018-q2-update-win32")
endif()
LIST(APPEND CMAKE_PROGRAM_PATH ${GCC_ARM_TOOLCHAIN})
# Specify the cross compiler
# The target triple needs to match the prefix of the binutils exactly
# (e.g. CMake looks for arm-none-eabi-ar)
set(CLANG_TARGET_TRIPLE arm-none-eabi)
set(GCC_ARM_TOOLCHAIN_PREFIX ${CLANG_CLANG_TARGET_TRIPLE})
set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})
set(CMAKE_ASM_COMPILER clang)
set(CMAKE_ASM_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})
# Don't run the linker on compiler check
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# Specify compiler flags
set(ARCH_FLAGS "-mcpu=cortex-a5 -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mno-unaligned-access")
set(CMAKE_C_FLAGS "-Wall ${ARCH_FLAGS}" CACHE STRING "Common flags for C compiler")
set(CMAKE_CXX_FLAGS "-Wall -std=c++17 -fno-exceptions -fno-rtti -fno-threadsafe-statics ${ARCH_FLAGS}" CACHE STRING "Common flags for C++ compiler")
set(CMAKE_ASM_FLAGS "-Wall ${ARCH_FLAGS} -x assembler-with-cpp" CACHE STRING "Common flags for assembler")
set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,-Map,kernel.map,--gc-sections -fuse-linker-plugin -Wl,--use-blx --specs=nano.specs --specs=nosys.specs" CACHE STRING "")
# C/C++ toolchain
set(GCC_ARM_SYSROOT "${GCC_ARM_TOOLCHAIN}/${GCC_ARM_TOOLCHAIN_PREFIX}")
# set(CMAKE_SYSROOT ${GCC_ARM_SYSROOT})
set(CMAKE_FIND_ROOT_PATH ${GCC_ARM_SYSROOT})
# Search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# For libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)