'gcc -lXext'成功但 libXext 似乎未链接
二进制文件已与 gcc 链接,使用:
gcc notion.o -Wl,-whole-archive ../ioncore/ioncore.a -Wl,-无整个存档 -L/usr/X11R6/lib -lX11 -lXext -lSM -lICE -Wl,-whole-archive -L../libmainloop -lmainloop -lextl -ltu -Wl,-no-whole-archive pkg-config --libs lua5.1
-ldl -lm -lrt -Xlinker --export-dynamic -o notion
链接成功 - 但是,在启动应用程序时,用户报告由于未定义的符号 (XShapeCombineRectangles
) 导致崩溃。 XShapeCombineRectangles
应该在 libXext 中可用。
事实上,通过“ldd”检查,Xext 并未列为该用户的共享库依赖项:
linux-gate.so.1 => (0x0068f000) libX11.so.6 => /usr/lib/i386-linux-gnu/libX11.so.6 (0x00ec7000) liblua5.1.so.0 => /usr/lib/i386-linux-gnu/liblua5.1.so.0 (0x00226000) libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0x005da000) libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0x005e1000) librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0x0032c000) libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00335000) libxcb.so.1 => /usr/lib/i386-linux-gnu/libxcb.so.1 (0x007d6000) /lib/ld-linux.so.2 (0x00882000) libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0x006dc000) libXau.so.6 => /usr/lib/i386-linux-gnu/libXau.so.6 (0x00110000) libXdmcp.so.6 => /usr/lib/i386-linux-gnu/libXdmcp.so.6 (0x00dd8000)
当我自己编译应用程序时,ldd 确实 显示 libXext,并且确实不会崩溃。
这里可能发生了什么?
(更多背景信息:此错误已报告于 http://sourceforge.net/tracker/?func=detail&aid=3427206&group_id=314802&atid=1324528)
A binary has been linked with gcc using:
gcc notion.o -Wl,-whole-archive ../ioncore/ioncore.a
-Wl,-no-whole-archive -L/usr/X11R6/lib -lX11 -lXext -lSM -lICE
-Wl,-whole-archive -L../libmainloop -lmainloop -lextl -ltu
-Wl,-no-whole-archive pkg-config --libs lua5.1
-ldl -lm -lrt -Xlinker
--export-dynamic -o notion
Linking succeeds - however, when starting the application, a user reports a crash due to an undefined symbol (XShapeCombineRectangles
). XShapeCombineRectangles
should be available in libXext.
Indeed, checking with 'ldd', Xext is not listed as a shared library dependency for this user:
linux-gate.so.1 => (0x0068f000) libX11.so.6 => /usr/lib/i386-linux-gnu/libX11.so.6 (0x00ec7000) liblua5.1.so.0 => /usr/lib/i386-linux-gnu/liblua5.1.so.0 (0x00226000) libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0x005da000) libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0x005e1000) librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0x0032c000) libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00335000) libxcb.so.1 => /usr/lib/i386-linux-gnu/libxcb.so.1 (0x007d6000) /lib/ld-linux.so.2 (0x00882000) libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0x006dc000) libXau.so.6 => /usr/lib/i386-linux-gnu/libXau.so.6 (0x00110000) libXdmcp.so.6 => /usr/lib/i386-linux-gnu/libXdmcp.so.6 (0x00dd8000)
When I compile the application myself, ldd does show libXext, and indeed does not crash.
What could be going on here?
(More context: this bug was reported at http://sourceforge.net/tracker/?func=detail&aid=3427206&group_id=314802&atid=1324528 )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的链接器(或 gcc)很可能会在幕后自动添加
--as-needed
,而您系统上的XShapeCombineRectangles
来自某个库other 比 libXext 强。您可以在链接中找出哪个库定义了
XShapeCombineRectangles
符号:只需将-Wl,-y,XShapeCombineRectangles
添加到您的链接行即可。添加
-v
将显示是否有任何--as-needed
参数在起作用。您可以通过将
-Wl,--no-as-needed,-lXext
附加到链接行来强制最终的可执行文件引用libXext
。更新:我误解了这个问题(而且你的表述非常糟糕)。
重申一下:
ldd
显示对 libXext 的依赖,app
ldd app
时,不显示 libXextde.so: undefined symbol XShapeCombineRectangles
正确,则可能是
libXext.a
,但不是libXext.so
XShapeCombineRectangles
,仅调用de.so
中的代码>de.so
时,其链接行上没有-lXext
。安装 libXext.so 或使用 -u XShapeCombineRectangles 链接主应用程序可能会解决该问题。
要了解该问题,您可能需要阅读此。
我的猜测是,
XShapeCombineRectangles
没有从主可执行文件中引用,因此没有从libXext.a
“书架”中提取,因此尽管- 也没有从主可执行文件中导出-导出动态
。It's likely that your linker (or gcc) automagically adds
--as-needed
behind the scenes, and that on your systemXShapeCombineRectangles
comes from some library other than libXext.You can find out which library defines the
XShapeCombineRectangles
symbol in your link: just add-Wl,-y,XShapeCombineRectangles
to your link line.Adding
-v
will show if any--as-needed
arguments are at play or not.You may be able to force the final executable to reference
libXext
by appending-Wl,--no-as-needed,-lXext
to the link line.Update: I misunderstood the question (and you've formulated it exceedingly poorly).
To restate:
ldd
shows dependency on libXextapp
ldd app
does not show libXextdlopen("de.so", ...)
on end-user system, this fails withde.so: undefined symbol XShapeCombineRectangles
If above points are correct, it's likely that
libXext.a
, but notlibXext.so
XShapeCombineRectangles
, only code inde.so
doesde.so
is linked, there is no-lXext
on its link line.Either installing
libXext.so
, or linking the main application with-u XShapeCombineRectangles
will likely solve the problem.To understand the problem, you might want to read this.
My guess is that
XShapeCombineRectangles
is not referenced from main executable, hence not pulled from thelibXext.a
"bookshelf", hence not exported from the main executable despite--export-dynamic
.