我在 32 位 Fedora Core 9 机器上静态构建了 X11R5 库。然后我构建了一个使用 X11 的应用程序并静态链接它。到目前为止,一切都很好。 ldd 报告它是一个静态链接的应用程序。我在本地运行就可以了。但是当我将其复制到 64 位 FC9 机器时,失败如下:
assistant.static: xcb_io.c:228: _XSend: 断言 `!dpy->xcb->request_extra' 失败。
已中止
当我运行 strace 时,它似乎试图打开 libXfixes.so:
...
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/libXfixes.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/libXfixes.so", O_RDONLY) = -1 ENOENT (No such file or directory)
munmap(0xf7bf9000, 123447) = 0
open("libXfixes", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 8
fstat64(0x8, 0xff86a9e8) = 0
mmap2(NULL, 123447, PROT_READ, MAP_PRIVATE, 8, 0) = 0xfffffffff7bf9000
close(8) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/libXfixes", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/libXfixes", O_RDONLY) = -1 ENOENT (No such file or directory)
munmap(0xf7bf9000, 123447) = 0
open("libXfixes.so.4", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 8
fstat64(0x8, 0xff86a9e8) = 0
mmap2(NULL, 123447, PROT_READ, MAP_PRIVATE, 8, 0) = 0xfffffffff7bf9000
close(8) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/libXfixes.so.4", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/libXfixes.so.4", O_RDONLY) = -1 ENOENT (No such file or directory)
munmap(0xf7bf9000, 123447) = 0
open("libXfixes", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 8
fstat64(0x8, 0xff86a9e8) = 0
mmap2(NULL, 123447, PROT_READ, MAP_PRIVATE, 8, 0) = 0xfffffffff7bf9000
close(8) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/libXfixes", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/libXfixes", O_RDONLY) = -1 ENOENT (No such file or directory)
munmap(0xf7bf9000, 123447) = 0
write(2, "assistant.static: xcb_io.c:228: "..., 85assistant.static: xcb_io.c:228: _XSend: Assertion `!dpy->xcb->request_extra' failed.
我不明白为什么静态链接的应用程序会尝试打开共享的 X 库。难道运行应用程序所需的所有内容都不应通过静态链接包含在内(当然应用程序进行的任何 Linux 系统调用除外,这些调用需要在外部处理)。
感谢您的解释!
最佳答案
X11 动态加载库,并且可能加载 64 位库而不是 32 位版本。
在运行时加载模块是正常的 - 就像加载插件或驱动程序时一样。而且由于模块是动态链接到 X11 本身的,因此您会发现自己陷入困境。
就我个人而言,我从来没有幸运地静态链接过 X11 - 您真的需要吗?
关于x11 - 为什么静态 X11 应用程序在其他计算机上失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3269677/