ld.exe: unrecognized option ‘--major-image-version‘

本文讲述了在Windows环境中使用CMake、mingw32和gcc进行交叉编译时遇到的问题,重点在于正确设置CMAKE_SYSTEM_NAME在project指令之前。提供了解决方法和相关链接作为参考。

问题:在windows环境使用cmake+mingw32+gcc交叉工具链报错

原因:将project指令放到了set(CMAKE_SYSTEM_NAME Linux)之前

下面为CMakeLists.txt正确写法:

cmake_minimum_required(VERSION 3.0)

#set(CMAKE_C_COMPILER_WORKS 1)

#set(CMAKE_CXX_COMPILER_WORKS 1)

#set(CMAKE_ASM_COMPILER_WORKS 1)

set(CMAKE_C_COMPILER "aarch64-none-linux-gnu-gcc.exe")

set(CMAKE_CXX_COMPILER "aarch64-none-linux-gnu-g++.exe")

set(CMAKE_LINKER aarch64-none-linux-gnu-ld.exe)

set(CMAKE_SYSTEM_NAME Linux)

set(CMAKE_SYSTEM_PROCESSOR arm)

project(hello-aarch64)

set(src main.cpp)

add_executable(hello-aarch64 ${src})

参考:

https://blog.youkuaiyun.com/alex_mianmian/article/details/118143017

https://whycan.com/t_6682.html

It fails with the following output: Change Dir: 'N:/LED_TEST/cmake-build-debug-stm32cube/CMakeFiles/CMakeScratch/TryCompile-1765by' Run Build Command(s): M:/STM32CubeCLT_1.18.0/Ninja/bin/ninja.exe -v cmTC_1e276 [1/2] M:\Stm\stm32cubeclt\STM32CubeCLT_1.18.0\GNU-tools-for-STM32\bin\arm-none-eabi-gcc.exe -std=gnu11 -fdiagnostics-color=always -o CMakeFiles/cmTC_1e276.dir/testCCompiler.c.obj -c N:/LED_TEST/cmake-build-debug-stm32cube/CMakeFiles/CMakeScratch/TryCompile-1765by/testCCompiler.c [2/2] C:\Windows\system32\cmd.exe /C "cd . && M:\STM32CubeCLT_1.18.0\GNU-tools-for-STM32\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_1e276.dir/testCCompiler.c.obj -o cmTC_1e276.exe -Wl,--out-implib,libcmTC_1e276.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." FAILED: cmTC_1e276.exe C:\Windows\system32\cmd.exe /C "cd . && M:\STM32CubeCLT_1.18.0\GNU-tools-for-STM32\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_1e276.dir/testCCompiler.c.obj -o cmTC_1e276.exe -Wl,--out-implib,libcmTC_1e276.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." M:/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: unrecognized option '--major-image-version' M:/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: use the --help option for usage information collect2.exe: error: ld returned 1 exit status ninja: build stopped: subcommand failed. 什么情况
08-02
CMake Error at D:/ST/STM32CubeCLT_1.18.0/CMake/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message): The C compiler "D:/ST/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: 'C:/Users/20465/Desktop/AAA/cmake-build-debug-stm32/CMakeFiles/CMakeScratch/TryCompile-sgx873' Run Build Command(s): D:/ST/STM32CubeCLT_1.18.0/Ninja/bin/ninja.exe -v cmTC_47dfe [1/2] D:\ST\STM32CubeCLT_1.18.0\GNU-tools-for-STM32\bin\arm-none-eabi-gcc.exe -std=gnu11 -fdiagnostics-color=always -o CMakeFiles/cmTC_47dfe.dir/testCCompiler.c.obj -c C:/Users/20465/Desktop/AAA/cmake-build-debug-stm32/CMakeFiles/CMakeScratch/TryCompile-sgx873/testCCompiler.c [2/2] C:\Windows\system32\cmd.exe /C "cd . && D:\ST\STM32CubeCLT_1.18.0\GNU-tools-for-STM32\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_47dfe.dir/testCCompiler.c.obj -o cmTC_47dfe.exe -Wl,--out-implib,libcmTC_47dfe.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." FAILED: cmTC_47dfe.exe C:\Windows\system32\cmd.exe /C "cd . && D:\ST\STM32CubeCLT_1.18.0\GNU-tools-for-STM32\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_47dfe.dir/testCCompiler.c.obj -o cmTC_47dfe.exe -Wl,--out-implib,libcmTC_47dfe.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." D:/ST/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: unrecognized option '--major-image-version' D:/ST/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: use the --help option for usage information collect2.exe: error: ld returned 1 exit status ninja: build stopped: subcommand failed. CMake will not be able to correctly generate this project.
07-11
CMake Error at G:/Clion/CLion 2025.1.3/bin/cmake/win/x64/share/cmake-3.31/Modules/CMakeTestCCompiler.cmake:67 (message): The C compiler "G:/STM32CLT/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: 'G:/test/1135121/cmake-build-release-stm32/CMakeFiles/CMakeScratch/TryCompile-bg8yhg' Run Build Command(s): G:/STM32CLT/STM32CubeCLT_1.18.0/Ninja/bin/ninja.exe -v cmTC_720cb [1/2] G:\STM32CLT\STM32CubeCLT_1.18.0\GNU-tools-for-STM32\bin\arm-none-eabi-gcc.exe -std=gnu11 -fdiagnostics-color=always -o CMakeFiles/cmTC_720cb.dir/testCCompiler.c.obj -c G:/test/1135121/cmake-build-release-stm32/CMakeFiles/CMakeScratch/TryCompile-bg8yhg/testCCompiler.c [2/2] C:\WINDOWS\system32\cmd.exe /C "cd . && G:\STM32CLT\STM32CubeCLT_1.18.0\GNU-tools-for-STM32\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_720cb.dir/testCCompiler.c.obj -o cmTC_720cb.exe -Wl,--out-implib,libcmTC_720cb.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." FAILED: cmTC_720cb.exe C:\WINDOWS\system32\cmd.exe /C "cd . && G:\STM32CLT\STM32CubeCLT_1.18.0\GNU-tools-for-STM32\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_720cb.dir/testCCompiler.c.obj -o cmTC_720cb.exe -Wl,--out-implib,libcmTC_720cb.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." G:/STM32CLT/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: unrecognized option '--major-image-version' G:/STM32CLT/STM32CubeCLT_1.18.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: use the --help option for usage information collect2.exe: error: ld returned 1 exit status ninja: build stopped: subcommand failed.怎么解决
07-08
CMake Error at C:/ST/STM32CubeCLT_1.19.0/CMake/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message): The C compiler "C:/ST/STM32CubeCLT_1.19.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: 'D:/workspace_sy/stm32_Test/CLion_ST_Test1/CLion_ST_Test1/cmake-build-debug-stm32/CMakeFiles/CMakeScratch/TryCompile-u2v03u' Run Build Command(s): C:/ST/STM32CubeCLT_1.19.0/Ninja/bin/ninja.exe -v cmTC_c803a [1/2] C:\ST\STM32CubeCLT_1.19.0\GNU-tools-for-STM32\bin\arm-none-eabi-gcc.exe -std=gnu11 -fdiagnostics-color=always -o CMakeFiles/cmTC_c803a.dir/testCCompiler.c.obj -c D:/workspace_sy/stm32_Test/CLion_ST_Test1/CLion_ST_Test1/cmake-build-debug-stm32/CMakeFiles/CMakeScratch/TryCompile-u2v03u/testCCompiler.c [2/2] C:\WINDOWS\system32\cmd.exe /C "cd . && C:\ST\STM32CubeCLT_1.19.0\GNU-tools-for-STM32\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_c803a.dir/testCCompiler.c.obj -o cmTC_c803a.exe -Wl,--out-implib,libcmTC_c803a.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." FAILED: cmTC_c803a.exe C:\WINDOWS\system32\cmd.exe /C "cd . && C:\ST\STM32CubeCLT_1.19.0\GNU-tools-for-STM32\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_c803a.dir/testCCompiler.c.obj -o cmTC_c803a.exe -Wl,--out-implib,libcmTC_c803a.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." C:/ST/STM32CubeCLT_1.19.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: unrecognized option '--major-image-version' C:/ST/STM32CubeCLT_1.19.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: use the --help option for usage information collect2.exe: error: ld returned 1 exit status ninja: build stopped: subcommand failed. CMake will not be able to correctly generate this project.
最新发布
08-22
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值