cmake:我无法在ARM上链接“ nano specs”文件

时间:2018-12-11 21:58:10

标签: c++ cmake linker arm g++

我正在与编写cmake脚本同时学习stm32生​​态系统。我为此目的写了smt32工具链。当我构建简单的代码时,编译器会向我返回以下问题:

arm-none-eabi-g++: fatal error: /usr/lib/gcc/arm-none-eabi/7.1.0/../../../../arm-none-eabi/lib/nano.specs: attempt to rename spec 'link' to already defined spec 'nano_link'

我搜索了很多网站,但没有找到任何解决方案。这是我的工具链文件。

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_C_COMPILER arm-none-eabi-gcc CACHE STRING "CMAKE_C_COMPILER")
set(CMAKE_CXX_COMPILER arm-none-eabi-g++ CACHE STRING "CMAKE_CXX_COMPILER")
set(CMAKE_LINKER arm-none-eabi-ld CACHE STRING "CMAKE_LINKER")
set(CMAKE_SIZE arm-none-eabi-size CACHE STRING "CMAKE_SIZE")
set(CMAKE_OBJCOPY arm-none-eabi-objcopy CACHE STRING "CMAKE_OBJCOPY")

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(COMMON_FLAGS "-mcpu=cortex-m3")
set(COMMON_FLAGS "${COMMON_FLAGS} -c")
set(COMMON_FLAGS "${COMMON_FLAGS} -mfloat-abi=soft")
set(COMMON_FLAGS "${COMMON_FLAGS} -mthumb")
set(COMMON_FLAGS "${COMMON_FLAGS} -fdata-sections")
set(COMMON_FLAGS "${COMMON_FLAGS} -ffunction-sections")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "CFLAGS")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "CXXFLAGS")

set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${COMMON_FLAGS}")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS}" CACHE STRING "")

set(LINKER_FLAGS "-mcpu=cortex-m3")
set(LINKER_FLAGS "${LINKER_FLAGS} -mthumb")
set(LINKER_FLAGS "${LINKER_FLAGS} -lc")
set(LINKER_FLAGS "${LINKER_FLAGS} -lm")
set(LINKER_FLAGS "${LINKER_FLAGS} -lnosys")
set(LINKER_FLAGS "${LINKER_FLAGS} -specs=nano.specs")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")

我怎么了? CMake是否为每个编译器(g ++,gcc,as)复制链接器标志?

感谢您的帮助。

0 个答案:

没有答案