C 如何解决链接器脚本中的错误?
我创建了一个内存链接器脚本,并将其保存为EclipseIDE中的memory.ld:Project:properties:gcc linker:miscellaneous:I添加了-M-T memory.ld memory.ld:C 如何解决链接器脚本中的错误?,c,linux,gcc,linker,ld,C,Linux,Gcc,Linker,Ld,我创建了一个内存链接器脚本,并将其保存为EclipseIDE中的memory.ld:Project:properties:gcc linker:miscellaneous:I添加了-M-T memory.ld memory.ld: MEMORY { ram (rw) : ORIGIN = 0x4000000 , LENGTH = 2M } SECTIONS { RAM : { *(.myvarloc) } > ram } 在我的c程序中:我做了
MEMORY
{
ram (rw) : ORIGIN = 0x4000000 , LENGTH = 2M
}
SECTIONS
{
RAM : { *(.myvarloc)
} > ram }
在我的c程序中:我做了一个全球声明:
__attribute__ ((section(".myvarloc")))
uint8 measurements [30];
错误:
/usr/bin/ld: FEBRUARY section `.text' will not fit in region `ram'
/usr/bin/ld: region `ram' overflowed by 20018 bytes
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x2b): undefined reference to `__init_array_end'
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x31): undefined reference to `__init_array_start'
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x57): undefined reference to `__init_array_start'
/usr/bin/ld: FEBRUARY: hidden symbol `__init_array_end' isn't defined
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
根据所使用的编译器(GCC?)和所编译的处理器(x86?),编译器将在目标文件中生成多个段引用。最常见的是
.text
用于代码段,.data
用于初始化数据,.bss
用于未初始化数据。
您可以使用对象文件上的nm
实用程序查看编译器生成的段。我假设,在您提供自己的链接器脚本之前,环境已经自动和/或隐式地提供了一些默认脚本。但是现在你已经决定“自己动手”,你必须自己处理所有细节。
我无法验证详细信息,但您可以从以下部分开始:
SECTIONS
{
.bss : { *(.myvarloc) }
.bss : { *(.bss) }
.data : { *(.data) }
.text : { *(.text) }
}
我不确定这是否是您的GCC链接器的确切语法(这取决于版本),但您可以在中找到更多信息。错误是关于
.text
/ram
not.myvarloc
溢出。您的链接器脚本可能需要告诉链接器如何处理其余的代码/数据等。,不仅仅是如何处理。myvarloc部分非常感谢您的回复。你能给我举个例子吗?我只需要记忆部分。所以我喜欢上面的。我想在我的c程序中指定上面的一样吗??