【发布时间】:2020-03-16 20:22:41
【问题描述】:
我正在尝试理解 GCC 链接脚本并创建一个小演示来练习,但是我从 ld 得到了“语法错误”。我感谢任何 cmets 或建议。非常感谢!
你好.c
__attribute__((section(".testsection"))) volatile int testVariable;
你好.ld
MEMORY {
TEST_SECTION: ORIGIN = 0x43840000 , LENGTH = 0x50
}
SECTIONS{
.testsection: > TEST_SECTION /* Syntax error here*/
}
编译命令
gcc -T hello.ld -o hello hello.o
c:/gnu/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe:../hello.ld:20: syntax error
collect2.exe: error: ld returned 1 exit status
【问题讨论】:
-
你试过 .testsection : { (.testsection) } > TEST_SECTION
-
感谢您的评论,我尝试了 .testsection : { *(.testsection) } > TEST_SECTION,我没有收到错误,但我仍然遇到了与 testsection 相同的错误:{ (.测试部分)} > TEST_SECTION 。我不确定 .testsection : { *(.testsection) } > TEST_SECTION 是正确的方法。
-
.text : { *(.text*) } > rom 是我用于 .text、.rodata、.bss 等的,它们工作得很好,所以我想我会把它扔在那里.您是否阅读了 gnu 链接器文档?嗯,也许某些格式发生在评论中有星号,您的回复显示在括号前面。现在它显示星号
-
rom : ORIGIN = 0x08000000, LENGTH = 0x1000 原点值和长度之间的逗号怎么样?错误消息告诉您问题出在哪一行
-
你没有指出 ld 抱怨的是哪一行。