STM32使用CMake+MinGW+arm-none-eabi 编译通过
每个C都可以生成.obj文件,但是生成elf进行链接时候出现错误:unrecognized option '--major-image-version'
信息如下
PS D:\TEST\C2\build> make
[ 33%] Building C object CMakeFiles/S123.dir/111.c.obj
[ 66%] Building C object CMakeFiles/S123.dir/123.c.obj
[100%] Linking C executable S123.exe
f:/softtools/ide/gun/toolchain/10_2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: unrecognized option '--major-image-version'
f:/softtools/ide/gun/toolchain/10_2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: use the --help option for usage information
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles\S123.dir\build.make:114: S123.exe] Error 1
make[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/S123.dir/all] Error 2
make: *** [Makefile:90: all] Error 2
然后就简单做了个2个c文件的测试。也是同样问题。麻烦大牛给点意见,谢谢。
CMake 文件如下:
cmake_minimum_required(VERSION 3.10)
project(S123)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
# debug build?
set(DEBUG "1")
# optimization
set(OPT "-Og")
ENABLE_LANGUAGE(ASM)
set(CROSS_COMPILER_PATH "F:/SoftTools/IDE/GUN/Toolchain/10_2020-q4-major")
set(CMAKE_C_COMPILER "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-gcc")
MESSAGE(STATUS,"compiler is ${CMAKE_C_COMPILER}")
set(CMAKE_ASM_COMPILER "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-gcc")
set(CMAKE_CXX_COMPILER "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-g++")
set(CMAKE_OBJCOPY "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-objcopy")
set(CMAKE_OBJDUMP "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-objdump" )
set(CMAKE_SIZE "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-size" )
set(CMAKE_NM "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-nm" )
set(CMAKE_DEBUGER "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-gdb")
set(CMAKE_CPPFILT "${CROSS_COMPILER_PATH}/bin/arm-none-eabi-c++filt" )
set(CMAKE_FIND_ROOT_PATH "${CROSS_COMPILER_PATH}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
aux_source_directory(. DIR_TOOT_SRCS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
add_executable(${PROJECT_NAME} ${DIR_TOOT_SRCS})
#add_executable(${PROJECT_NAME} 123.c)
离线
--major-image-version
链接命令行, 这个选项去掉试一试.
上面这个是CMake自动生成的。就算手动去掉了--major-image-version,会报--minor-image-version错误
再去掉,会接着后面的错误……
离线
弄好了,Win下的VSC这两句要放在最开始,否则会认为要make win下的exe。置顶就可以了。
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
离线