gcc 无法使用cmakelists创建十六进制elf文件

ua4mk5z4  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(163)

我正在尝试使用cmakelists为我的binkled项目创建一个十六进制和elf文件,使用IAR文件。
编译是没有错误的cmake,但我没有看到文件在建设文件夹。我的目标是创建一个十六进制和精灵文件闪烁钱包后。
有人能告诉我我应该修改什么来解决这个问题吗?非常感谢
营销人员:

cmake_minimum_required(VERSION 3.7.2)

######################################################################
#
#   Project
#
######################################################################

project(blink_cortex_m0plus)
enable_language(ASM)

######################################################################
#
#   CPP Definitions
#
######################################################################

set(PROJECT_FLAGS_ARCH
    "-mcpu=cortex-m0plus \
     -mthumb"
)

set(PROJECT_LINKER_FLAGS
    "-Wl,-Map=${PROJECT_NAME}.map \
    -L${PROJECT_SOURCE_DIR}/../config/ \
    -Tlinker.ld"
)

set(PROJECT_C_FLAGS_WARNINGS   "${COMMON_FLAGS_WARNINGS} ${C_FLAGS_WARNINGS_EXTRA}")

######################################################################
#
#   Sources
#
######################################################################

set(PROJECT_INCLUDE_DIRS
    ${PROJECT_CONFIG_DIR}
    ${BLINK_DIR}/../
    ${CYPRESS_CORE_LIBRARY}
)

set(PROJECT_SRCS
    ${PROJECT_SOURCE_DIR}/main_cm0plus.c
    ${CYPRESS_PERIPHERAL_DRIVERS_LIBRARY}system_tviibe1m_cm0plus.c
    ${CYPRESS_PERIPHERAL_DRIVERS_LIBRARY}startup_cm0plus.S
)

######################################################################
#
#   TARGET
#
######################################################################

set (CMAKE_C_FLAGS   "${C_FLAGS} ${C_FLAGS_WARNINGS}  ${FLAGS_OPTIMIZATION} ${PROJECT_FLAGS_ARCH}")
set (CMAKE_ASM_FLAGS "${C_FLAGS}   ${C_FLAGS_WARNINGS}   ${FLAGS_OPTIMIZATION} ${PROJECT_FLAGS_ARCH}")
#set (CMAKE_CXX_FLAGS "${CXX_FLAGS} ${CXX_FLAGS_WARNINGS} ${FLAGS_OPTIMIZATION} ${PROJECT_FLAGS_ARCH}")
set (CMAKE_EXE_LINKER_FLAGS "${LINKER_FLAGS} ${PROJECT_LINKER_FLAGS} ${FLAGS_OPTIMIZATION} ${PROJECT_FLAGS_ARCH}")

set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(OBJCOPY arm-none-eabi-objcopy)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)

include_directories(
        ${PROJECT_INCLUDE_DIRS}
        ${CYPRESS_PERIPHERAL_DRIVERS_LIBRARY_INCLUDE_DIRS}
# )

add_executable(${PROJECT_NAME}.elf ${PROJECT_SRCS} ${CYPRESS_PERIPHERAL_DRIVERS_LIBRARY_SRCS})

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map")
set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.bin)

add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
        COMMAND ${OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
        COMMAND ${OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
        COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}")
ryevplcw

ryevplcw1#

我使用以下命令将其转换为.bin和.hex:

add_custom_command(TARGET ${APPLICATION}
    POST_BUILD
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMAND ${OBJCOPY} ARGS -O binary ${APPLICATION} ${APPLICATION_BIN}
    COMMAND ${OBJCOPY} ARGS -O ihex -R .eeprom -R .fuse -R .lock -R .signature ${APPLICATION} ${APPLICATION_HEX}
)

一个值得注意的差异是ARGS,如下所示:https://stackoverflow.com/a/53573133

相关问题