问题描述
我使用clang编译了一个GTK +程序,而不是gcc。到目前为止,除了我无法正确连接 ld 链接以外,还是很好的。
原始makefile调用gcc来执行链接,如下所示:
如果我简单地用上面的命令替换 gcc 和 clang ,我会从后者得到这个警告:
通过添加前3个对象,我避免了无法找到_start消息。但是后来我得到了前面提到的两个抱怨:
lockquote
_start
:(.text + 0x12):未定义引用
__ libc_csu_fini
/usr/lib/crt1.o:函数
_start
:(.text + 0x19):未定义引用
__ libc_csu_init
我尝试在列表中添加crtbegin.o和crtend.o,甚至在 crt1.o 之前都无济于事。什么是链接器的正确调用?
(后编辑):如果没有其他工作,有没有办法来抓住什么确切的参数 gcc 是当 gcc 用于链接时传递给 ld ?
您可以使用 -Wl,-export-dynamic
将 -export-dynamic
传递给ld,而无需clang知道它。
I'm compiled a GTK+ program using clang, rather than gcc. So far so good, except I can't have ld link correctly.
Original makefile called gcc to do the linking, like this:
If I simply substitute gcc with clang in the above command, I get this warning from the latter:
Problem is: clang doesn't recognize "-export-dynamic" as a linker option, so it doesn't pass it off to ld. This causes the references to external functions to be scrapped: when final binary is executed, neither the menu options nor the buttons react.
If I do final linking step with gcc the binary works perfectly (even though it was really compiled with clang and gcc only does the linking). Since I'm trying to completely replace gcc with clang in my machine, this is not acceptable.
So I tried this:
By adding first 3 objects I avoid the "can't find _start" message. But then I get the aforementioned two complaints:
I tried adding crtbegin.o and crtend.o at the list, even before crt1.o , to no avail. What is the linker's correct invocation?
(Post Edit): If nothing else works, is there a way to catch what exact parameters gcc is passing to ld when gcc is used for the linking?
You can use -Wl,-export-dynamic
to pass -export-dynamic
to ld without clang knowing about it.
这篇关于ld抱怨:在函数“_start”中,未定义对“__ libc_csu_fini”的引用。 &安培; " __ libc_csu_init"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!