您尚未登录。

楼主 # 2021-06-19 17:09:22

sjshe3326
会员
注册时间: 2020-10-19
已发帖子: 125
积分: 69.5

STM32使用CMake+MinGW+arm-none-eabi 编译通过 链接失败问题

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)

离线

#1 2021-06-19 17:32:37

哇酷小二
管理员
所在地: 你猜
注册时间: 2020-04-22
已发帖子: 3,388
积分: 1902
个人网站

Re: STM32使用CMake+MinGW+arm-none-eabi 编译通过 链接失败问题

--major-image-version 

链接命令行, 这个选项去掉试一试.





离线

楼主 #2 2021-06-19 18:14:05

sjshe3326
会员
注册时间: 2020-10-19
已发帖子: 125
积分: 69.5

Re: STM32使用CMake+MinGW+arm-none-eabi 编译通过 链接失败问题

哇酷小二 说:

--major-image-version 

链接命令行, 这个选项去掉试一试.

上面这个是CMake自动生成的。就算手动去掉了--major-image-version,会报--minor-image-version错误
再去掉,会接着后面的错误……

离线

楼主 #3 2021-06-21 09:26:34

sjshe3326
会员
注册时间: 2020-10-19
已发帖子: 125
积分: 69.5

Re: STM32使用CMake+MinGW+arm-none-eabi 编译通过 链接失败问题

弄好了,Win下的VSC这两句要放在最开始,否则会认为要make win下的exe。置顶就可以了。

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn