我正在尝试使用 ARM GNU Toolchain(目前版本 11.3)构建 ARM 应用程序。为此,我有一个主程序,需要链接到一个静态库
foo
,该库间接依赖于另一个静态库 bar
。
将库和主程序编译为ELF目标文件成功。但是每当我尝试通过运行例如将程序和库的任意组合链接在一起时
arm-none-eabi-gcc foo.o bar.o -o foobar.o
我收到以下形式的致命错误:
c:/arm_toolchain_11/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: foo.o: in function `no symbol':
(.text.fooSome_Function+0x0): multiple definition of `no symbol'; foo.o:(.text.fooSome_OtherFunction+0x0): first defined here
...
c:/arm_toolchain_11/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: foo.o: .symtab local symbol at index 8830 (>= sh_info of 8046)
c:/arm_toolchain_11/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: foo.o: error adding symbols: bad value
collect2.exe: error: ld returned 1 exit status
我在任何地方都找不到这些类型的链接器错误通常意味着什么。
在目标文件上运行
file
将返回以下内容:
# file foo.o
foo.o: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), not stripped
# file bar.o
bar.o: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), not stripped
您可以看到结果匹配。
在文件上运行
readelf -sW
给出的输出结尾如下:
readelf: Warning: local symbol 8830 found at index >= .symtab's sh_info value of 8046
(仅数字不同)。对我来说,这表明 GCC 以某种方式生成了无效的 ELF 文件,但这似乎不太可能。
最后,我在 Windows 上的 MSYS2 中构建它。
不幸的是,我无法提供源代码。
有谁可以进一步阐明这一点吗?
提前谢谢您!
致以诚挚的问候,
约书亚
这个命令:
arm-none-eabi-gcc foo.o bar.o -o foobar.o
可能是错误的。
您要求 GCC 链接一个完整可执行程序,并将该程序命名为
foobar.o
。
您打算将
foo.o
和 bar.o
合并到单个 object 文件 foobar.o
中,在这种情况下,您将链接两个可重定位目标文件并构建另一个可重定位目标文件,并且必须使用 -r
标志。
或者您确实正在尝试链接一个完整的可执行程序,在这种情况下,您应该 not 命名生成的可执行文件
foobar.o
以避免让每个人感到困惑。
显示您的实际链接命令可能会有所帮助。