我正在尝试将自定义目标添加到我的 Cmake 项目中,它将从 .elf 输出 .hex 文件。这是我使用的一段脚本:
....
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/${CMAKE_BUILD_TYPE}")
....
target_link_libraries(${CMAKE_PROJECT_NAME}.elf)
set(COMD "${CMAKE_OBJCOPY} -Oihex ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_PROJECT_NAME}.elf ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_PROJECT_NAME}.hex")
add_custom_target(${CMAKE_PROJECT_NAME}.hex DEPENDS ${CMAKE_PROJECT_NAME}.elf COMMAND ${COMD})
建筑最终是这样的:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/captain/test
[100%] Built target test.elf
/bin/sh: 1: arm-none-eabi-objcopy -Oihex /home/captain/test/Release/test.elf /home/captain/test/Release/test.hex: not found
.... blah blah blah ...
直接运行:
arm-none-eabi-objcopy -Oihex /home/captain/test/Release/test.elf /home/captain/test/Release/test.hex
按预期工作。怎么可能?