gpt4 book ai didi

gcc - 如何告诉 CMake 为 GCC 指定多个链接描述文件?

转载 作者:行者123 更新时间:2023-12-03 08:41:54 25 4
gpt4 key购买 nike

我正在使用 CMake 3.17 和 GNU ARM 工具链,并且正在尝试将构建从 Eclipse 迁移到 CMake。Eclipse 构建的一部分指定了在链接时使用的多个链接器脚本文件,因此我设置了 CMakeLists。 txt 文件如下所示:

target_link_options(${application_name} PRIVATE
-mcpu=cortex-m4
-mthumb
-mfloat-abi=hard
-mfpu=fpv4-sp-d16
-fmessage-length=0
-fsigned-char
-ffunction-sections
-fdata-sections
-flto
-Wall
-Xlinker --gc-sections
-Wl,-Map,${map_file}
-T ${CMAKE_SOURCE_DIR}/ldscripts/libs.ld
-T ${CMAKE_SOURCE_DIR}/ldscripts/mem.ld
-T ${CMAKE_SOURCE_DIR}/ldscripts/sections.ld
)

但是当我运行 make 时,第二个和第三个文件的 -T 选项被吞没。这是成功编译所有源后运行 make VERBOSE=1 时得到的结果。链接器命令行后跟有关缺少 -T 选项的警告:

Linking CXX executable StartupSequence.elf
/D/gcc-arm-none-eabi-9-2019-q4/bin/arm-none-eabi-g++.exe --specs=nano.specs --specs=nosys.specs -g -Og -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -flto -Wall -Xlinker --gc-sections -Wl,-Map,StartupSequence.map -T C:/svn/startup_sequence/ldscripts/libs.ld C:/svn/startup_sequence/ldscripts/mem.ld C:/svn/startup_sequence/ldscripts/sections.ld @CMakeFiles/StartupSequence.dir/objects1.rsp -o StartupSequence.elf ../Drivers/CMSIS/DSP/Lib/libarm_cortexM4lf_math.a ../Middlewares/Third_Party/mbedTLS/library/libmbedcrypto.a
d:/gcc-arm-none-eabi-9-2019-q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: C:/svn/startup_sequence/ldscripts/sections.ld contains output sections; did you forget -T?

为什么最后两个文件的 -T 没有正确发送到命令行?

我尝试将链接脚本规范分成三个对 target_link_options 的单独调用,并将每个脚本规范用双引号引起来,但似乎没有效果。

最佳答案

默认情况下,CMake 去重复编译和链接选项。也就是说,多个 -T 选项合并为一个选项。

CMake 不知道哪些选项实际上与其他参数绑定(bind),但提供了一个 SHELL: 机制来定义此类选项:

target_link_options(${application_name} PRIVATE
"SHELL:-T ${CMAKE_SOURCE_DIR}/ldscripts/libs.ld"
"SHELL:-T ${CMAKE_SOURCE_DIR}/ldscripts/mem.ld"
"SHELL:-T ${CMAKE_SOURCE_DIR}/ldscripts/sections.ld"
)

此机制在 documentation 中进行了描述。对于target_link_options命令。


相同的机制适用于传递给 target_compile_options 的编译器选项,请参阅 questionmy answer为了它。

关于gcc - 如何告诉 CMake 为 GCC 指定多个链接描述文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62478709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com