【发布时间】:2020-05-17 07:50:42
【问题描述】:
我正在尝试使用 CMake 和实际的 GNU 工具链版本 9_2019_q4_major 从 STM32Cube_FW_F4_V1.24.0 运行 GPIO_EXTI 示例Windows 通过 Cygwin 终端。 该项目应在 STM32F4-DISCOVERY 板上运行。
我有一个基于Cmake File 的 CMakeLists.txt 文件。
cmake_minimum_required (VERSION 3.5)
project(F4cmake)
enable_language(C ASM)
SET(TARGET F4cmake)
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR arm)
# SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
add_definitions(-DSTM32F407xx)
add_definitions(-DUSE_STM32F4_DISCO)
add_definitions(-DUSE_HAL_DRIVER)
add_definitions(-D__MICROLIB)
add_definitions(-D_RTE_)
SET (STARTUP D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S)
message (STATUS "[DBG]: ${STARTUP}")
SET(SYSTEM D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/system_stm32f4xx.c)
SET(HAL_PATH D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver)
SET (CMSIS_SRCS
# ${CMAKE_CURRENT_SOURCE_DIR}/../../../Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_gcc.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_armcc.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_compiler.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_version.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/core_cm4.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/mpu_armv7.h
${HAL_PATH}/Src/stm32f4xx_hal_pwr.c
${HAL_PATH}/Inc/stm32f4xx_hal_pwr.h
${HAL_PATH}/Src/stm32f4xx_hal_cortex.c
${HAL_PATH}/Inc/stm32f4xx_hal_cortex.h
${HAL_PATH}/Src/stm32f4xx_hal_gpio.c
${HAL_PATH}/Inc/stm32f4xx_hal_gpio.h
${HAL_PATH}/Src/stm32f4xx_hal_flash.c
${HAL_PATH}/Inc/stm32f4xx_hal_flash.h
${HAL_PATH}/Src/stm32f4xx_hal_spi.c
${HAL_PATH}/Inc/stm32f4xx_hal_spi.h
${HAL_PATH}/Src/stm32f4xx_hal_rcc.c
${HAL_PATH}/Inc/stm32f4xx_hal_rcc.h
${HAL_PATH}/Src/stm32f4xx_hal_flash_ex.c
${HAL_PATH}/Inc/stm32f4xx_hal_flash_ex.h
${HAL_PATH}/Src/stm32f4xx_hal_rcc_ex.c
${HAL_PATH}/Inc/stm32f4xx_hal_rcc_ex.h
${HAL_PATH}/Src/stm32f4xx_hal_i2c.c
${HAL_PATH}/Inc/stm32f4xx_hal_i2c.h
${HAL_PATH}/Src/stm32f4xx_hal.c
${HAL_PATH}/Inc/stm32f4xx_hal.h
${HAL_PATH}/Src/stm32f4xx_hal_pwr_ex.c
${HAL_PATH}/Inc/stm32f4xx_hal_pwr_ex.h
${HAL_PATH}/Src/stm32f4xx_hal_dma.c
${HAL_PATH}/Inc/stm32f4xx_hal_dma.h
${HAL_PATH}/Src/stm32f4xx_hal_i2c_ex.c
${HAL_PATH}/Inc/stm32f4xx_hal_i2c_ex.h
)
SET (BSP_SRCS
D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c
D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.h
)
message (STATUS "[DBG]: ${BSP_SRCS}")
SET (APP_SRCS
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/main.c
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/stm32f4xx_it.c
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/main.h
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/stm32f4xx_hal_conf.h
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/stm32f4xx_it.h
)
message (STATUS "[DBG]: ${APP_SRCS}")
include_directories (
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc
D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include
)
set_source_files_properties(D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
set_property(SOURCE D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S PROPERTY LANGUAGE C)
SET (LINKER_SCRIPT D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/SW4STM32/STM32F4-Discovery/STM32F407VGTx_FLASH.ld)
message (STATUS "[DBG]: ${LINKER_SCRIPT}")
SET(USER_SOURCES ${STARTUP} ${SYSTEM} ${CMSIS_SRCS} ${BSP_SRCS} ${APP_SRCS} ${LINKER_SCRIPT})
message(STATUS "[DBG]: ${USER_SOURCES}")
SET(COMPILER_PATH C:/GnuToolChain/9_2019_q4_major/bin)
SET(CMAKE_ASM_COMPILER "${COMPILER_PATH}/arm-none-eabi-as")
SET(CMAKE_C_COMPILER "${COMPILER_PATH}/arm-none-eabi-gcc")
SET(CMAKE_CXX_COMPILER "${COMPILER_PATH}/arm-none-eabi-g++")
SET(CMAKE_C_LINK_EXECUTABLE "${COMPILER_PATH}/arm-none-eabi-ld")
SET(CMAKE_OBJCOPY "${COMPILER_PATH}/arm-none-eabi-objcopy")
SET(CMAKE_OBJDUMP "${COMPILER_PATH}/arm-none-eabi-objdump")
SET(CMAKE_SIZE "${COMPILER_PATH}/arm-none-eabi-size")
SET(CMAKE_ASM_FLAGS "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16")
SET(CMAKE_C_FLAGS "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fno-common -fsigned-char -fmessage-length=0 -Wall -Wextra -Wshadow -Os -ffunction-sections -fdata-sections -g -std=c11")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl, --specs=nosys.specs --specs=nano.specs -Wl,--gc-sections -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mabi=aapcs -Wl,-T ${LINKER_SCRIPT}")#-Wl,-map=${TARGET}.map,--cref #-u _printf_float -u _scanf_float
add_executable(${TARGET}.elf ${USER_SOURCES})
set_target_properties(${TARGET}.elf PROPERTIES LINKER_LANGUAGE C)
add_custom_target (${TARGET}.bin
DEPENDS ${TARGET}.elf
COMMAND ${CMAKE_OBJCOPY} -O binary ${TARGET}.elf ${TARGET}.bin
)
add_custom_target (${TARGET}.lst
DEPENDS ${TARGET}.elf
COMMAND ${CMAKE_OBJDUMP} -Sdh ${TARGET}.elf > ${TARGET}.lst
)
CMakeLists.txt 文件的输出是:
> $ cmake.exe -G"Unix Makefiles" ..
>
> -- The C compiler identification is unknown
> -- The CXX compiler identification is GNU 7.4.0
> -- Check for working C compiler: C:/cygwin/bin/cc
> -- Check for working C compiler: C:/cygwin/bin/cc -- works
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> -- Check for working CXX compiler: C:/cygwin/bin/c++.exe
> -- Check for working CXX compiler: C:/cygwin/bin/c++.exe -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> -- The ASM compiler identification is unknown
> -- Found assembler: C:/cygwin/bin/cc
> -- Warning: Did not find file Compiler/-ASM
> -- [DBG]:
>
> D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S
> -- [DBG]: D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.h
> -- [DBG]: D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/main.c;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Sr
> c/stm32f4xx_it.c;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/main.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_
> EXTI/Inc/stm32f4xx_hal_conf.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/stm32f4xx_it.h
> -- [DBG]: D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/SW4STM32/STM32F4-Discovery/STM32F407VGTx_FLASH.ld
> -- [DBG]: D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GP
> IO/GPIO_EXTI/Src/system_stm32f4xx.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/I
> nclude/stm32f407xx.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_gcc.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_armcc.h;D:/STM32Cube_FW_F4_V1.24 .0/Drivers/CMSIS/Core/Include/cmsis_compiler.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_version.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/core_cm4
> .h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/mpu_armv7.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;D:/STM32Cube_FW_F4_V1.24.0/Dri
> vers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_H
> AL_Driver/Inc/stm32f4xx_hal_cortex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/s
> tm32f4xx_hal_gpio.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_fla
> sh.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.h;D:/STM32Cube_F
> W_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;D:/STM32Cube_FW_F4_V1.24.0/Driver
> s/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4
> xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver
> /Src/stm32f4xx_hal_i2c.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.
> c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;D:/STM32Cube_FW_F4
> _V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers /STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_D
> river/Inc/stm32f4xx_hal_i2c_ex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_disc
> overy.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/main.c;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/ stm32f4xx_it.c;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/main.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EX
> TI/Inc/stm32f4xx_hal_conf.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/stm32f4xx_it.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/
> Examples/GPIO/GPIO_EXTI/SW4STM32/STM32F4-Discovery/STM32F407VGTx_FLASH.ld
> -- Configuring done
> -- Generating done
> -- Build files have been written to: D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/build
在此之后,我在 Cygwin 终端“make”中输入,我得到以下结果:
$ make
Scanning dependencies of target F4cmake.elf
[ 5%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S.obj
[ 10%] Building C object CMakeFiles/F4cmake.elf.dir/Src/system_stm32f4xx.c.obj
[ 15%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c.obj
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c: In function 'HAL_PWR_EnterSLEEPMode':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c:365:38: warning: unused parameter 'Regulator' [-Wunused-parameter]
365 | void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
| ~~~~~~~~~^~~~~~~~~
[ 21%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c.obj
[ 26%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c.obj
[ 31%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c.obj
[ 36%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c.obj
[ 42%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c.obj
[ 47%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c.obj
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c: In function 'FLASH_MassErase':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c:953:60: warning: unused parameter 'Banks' [-Wunused-parameter]
953 | static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks)
| ~~~~~~~~~^~~~~
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c: In function 'FLASH_OB_EnableWRP':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c:1032:74: warning: unused parameter 'Banks' [-Wunused-parameter]
1032 | static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks)
| ~~~~~~~~~^~~~~
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c: In function 'FLASH_OB_DisableWRP':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c:1068:75: warning: unused parameter 'Banks' [-Wunused-parameter]
1068 | static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Banks)
| ~~~~~~~~~^~~~~
[ 52%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c.obj
[ 57%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c.obj
[ 63%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c.obj
[ 68%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c.obj
[ 73%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c.obj
[ 78%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c.obj
[ 84%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c.obj
D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c: In function 'I2Cx_Error':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c:454:32: warning: unused parameter 'Addr' [-Wunused-parameter]
454 | static void I2Cx_Error(uint8_t Addr)
| ~~~~~~~~^~~~
[ 89%] Building C object CMakeFiles/F4cmake.elf.dir/Src/main.c.obj
[ 94%] Building C object CMakeFiles/F4cmake.elf.dir/Src/stm32f4xx_it.c.obj
[100%] Linking C executable F4cmake.elf.exe
C:\GnuToolChain\9_2019_q4_major\bin\arm-none-eabi-ld.exe: no input files
make[2]: *** [CMakeFiles/F4cmake.elf.dir/build.make:338: F4cmake.elf.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/F4cmake.elf.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
*** [Makefile:84: all] Error 2
我不明白,为什么链接器说他没有输入文件。
在 CMakeLists.txt 中,我明确添加了链接器 (arm-none-eabi-ld.exe),因为如果我不添加链接器,我会遇到其他故障,并且 MAKE 正在使用我不使用的其他链接器明白为什么。
[ 89%] Building C object CMakeFiles/F4cmake.elf.dir/Src/main.c.obj
[ 94%] Building C object CMakeFiles/F4cmake.elf.dir/Src/stm32f4xx_it.c.obj
[100%] Linking C executable F4cmake.elf.exe
c:/gnutoolchain/9_2019_q4_major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find : Invalid argument
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/F4cmake.elf.dir/build.make:338: F4cmake.elf.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/F4cmake.elf.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
我没有看到我的失败。
- 谁能告诉我我做错了什么?
- 为什么 make 使用不同的链接器?
- 如何修复 CMakeLists.txt 文件,使 Make 可以生成 *.elf 输出文件?
谢谢
【问题讨论】:
-
请将您的日志作为文本发布在您的问题帖子中。请不要发布日志输出的图像。
-
错误消息
cannot find : Invalid argument闻起来就像您的链接器标志中有一些 empty 字符串。使用make VERBOSE=1,您可能会看到用于链接的完整命令行。至于设置变量CMAKE_CXX_LINK_EXECUTABLE注意,这是不是可执行文件而是规则;请参阅answer 了解更多信息。 -
还要注意,像
CMAKE_C_COMPILER、CMAKE_SYSTEM_NAME这样的编译器特定 设置通常是单独的toolchain 文件的一部分,而不是CMakeLists.txt文件的一部分。您是否注意到 CMake 输出中的Check for working C compiler: C:/cygwin/bin/cc行?这是因为 CMake 将您的项目视为使用主机编译器,而不是被交叉编译。工具链设置(作为CMAKE_TOOLCHAIN_FILE传递的文件)和代码(CMakeLists.txt)的分离使您的项目真正跨平台。 -
感谢您的建议。我有几个问题,为什么上面的代码不起作用。我创建了一个 toolchain.cmake 文件。我对编译器/链接器设置以及它们的编写方式也有疑问。显然,在 Windows 中,需要将所有参数写在一行中,而不是将它们分开。就这样。我将用运行代码回答这篇文章。如果你喜欢,你可以检查代码。谢谢
标签: cmake gnu-make stm32 stm32f4discovery stm32f4