ld抱怨:在函数“_start”中,未定义对“__ libc_csu_fini”的引用。 &安培; " __ libc_csu_init" [英] ld complains: in function "_start", undefined reference to "__libc_csu_fini" & "__libc_csu_init"
问题描述
我使用clang编译了一个GTK +程序,而不是gcc。到目前为止,除了我无法正确连接 ld 链接以外,还是很好的。
原始makefile调用gcc来执行链接,如下所示:
gcc -g -O2 -export-dynamic -o my_application somefile.o another.o -pthread -lgnomeui-2 -lSM -lICE - lbonoboui-2-lgnomevfs-2-lgomene-2 -lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation-10RBit-2-lart_lgpl_2-lgconf-2-lglade-2.0 -lglk-x11-2.0 -lgdk-x11- 2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 - lxml2 -pthread -lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -lxml2 -lgthread-2.0 -lrt -lglib-2.0
如果我简单地用上面的命令替换 gcc 和 clang ,我会从后者得到这个警告:
clang:warning:编译期间未使用的参数:'-e xport-dynamic'
问题是:clang不会将-export-dynamic识别为链接器选项,因此它不会将它传递给 ld 。这会导致对外部函数的引用被废弃:执行最终的二进制文件时,菜单选项和按钮都不会起作用。
如果我使用gcc进行最终链接步骤,二进制完美工作(即使它真的编译与叮当和GCC只做链接)。因为我试图用我的机器中的clang完全替代gcc,所以这是不可接受的。
所以我试过了:
ld /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtn.o -g -O2 -export-dynamic my_application somefile.o another 1-O-亚硝基-2-烯丙基-2-烯丙基-2-烯丙基-2-烯丙基-2-烯丙基-2-烯丙基-2-羰基 - 活化-10Bit-2-lart_lgpl_2-lgconf-2-lglade -2.0 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule -2.0 -lgthread-2.0 -lrt -lglib-2.0 -lxml2 -lststreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -lxml2 -lgthread-2.0 -lrt -lglib-2.0
通过添加前3个对象,我避免了无法找到_start消息。但是后来我得到了前面提到的两个抱怨:
/usr/lib/crt1.o:在函数
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:
gcc -g -O2 -export-dynamic -o my_application somefile.o another.o -pthread -lgnomeui-2 -lSM -lICE -lbonoboui-2 -lgnomevfs-2 -lgnomecanvas-2 -lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation -lORBit-2 -lart_lgpl_2 -lgconf-2 -lglade-2.0 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lxml2 -pthread -lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -lxml2 -lgthread-2.0 -lrt -lglib-2.0
If I simply substitute gcc with clang in the above command, I get this warning from the latter:
clang: warning: argument unused during compilation: '-e xport-dynamic'
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:
ld /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtn.o -g -O2 -export-dynamic my_application somefile.o another.o -o -lgnomeui-2 -lSM -lICE -lbonoboui-2 -lgnomevfs-2 -lgnomecanvas-2 -lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation -lORBit-2 -lart_lgpl_2 -lgconf-2 -lglade-2.0 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lxml2 -lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -lxml2 -lgthread-2.0 -lrt -lglib-2.0
By adding first 3 objects I avoid the "can't find _start" message. But then I get the aforementioned two complaints:
/usr/lib/crt1.o: In function
_start
: (.text+0x12): undefined reference to__libc_csu_fini
/usr/lib/crt1.o: In function_start
: (.text+0x19): undefined reference to__libc_csu_init
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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!