在 64 位 Ubuntu 中构建 32 位应用程序
经过几个小时的谷歌搜索后,我决定放弃并询问各位专家。我正在尝试在我的 64 位 Ubuntu 11.10 中构建一个 32 位应用程序(如果有人感兴趣,请使用 xgap)。我在 makefile 中添加了 CFLAGS=-m32 和 LDFLAGS=-L/usr/lib32 。这些对象被内置为 32 位精细。最后一步是将 X windows 的所有对象和库链接到这个可执行文件中——xgap。不知怎的,它一直给我这个错误:
gcc -o xgap xcmds.o utils.o gapgraph.o gaptext.o pty.o popdial.o xgap.o selfile.o -L/usr/lib32 -lXaw -lXmu -lXt -lXext -lX11 -lSM -lICE
/usr/bin/ld: skipping incompatible /usr/lib32/libXmu.so when searching for -lXmu
...
/usr/bin/ld: i386 architecture of input file `xcmds.o' is incompatible with i386:x86-64 output
...
我已经安装了ia32-libs和mutilib支持。我想我只需要强制链接器生成 i386 输出。我尝试在 gcc 命令中添加两个 ld 标志,如上所示:-melf_i386 和 -oformat elf32-i386。但发生的情况是 gcc 不再在 /usr/lib32 中搜索 32 位库。我想知道是否需要按固定顺序放置这些标志?
感谢您的任何想法和帮助!
编辑:当我在最后一个 gcc 命令中添加 -m32 标志时(我相信是链接阶段),即使我有 -L/usr/lib32 标志,gcc 也不会搜索/usr/lib32 不再(真的很奇怪......)并生成以下错误:
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../libXaw.so when searching for -lXaw
/usr/bin/ld: skipping incompatible /usr/lib/libXaw.so when searching for -lXaw
/usr/bin/ld: cannot find -lXaw
collect2: ld returned 1 exit status
任何人都知道为什么会发生这种情况?我正在使用自动工具来配置和制作。我真的很擅长修改这些脚本文件。
After hours of googling, I decide to give up and ask you experts. I am trying to build a 32-bit application (xgap if anyone interested) in my 64 Ubuntu 11.10. I added the CFLAGS=-m32 and the LDFLAGS=-L/usr/lib32 in the makefile. The objects are built into 32 bit fine. The last step is to link all the objects and libraries for X windows into this executable---xgap. Somehow it keeps giving me this error:
gcc -o xgap xcmds.o utils.o gapgraph.o gaptext.o pty.o popdial.o xgap.o selfile.o -L/usr/lib32 -lXaw -lXmu -lXt -lXext -lX11 -lSM -lICE
/usr/bin/ld: skipping incompatible /usr/lib32/libXmu.so when searching for -lXmu
...
/usr/bin/ld: i386 architecture of input file `xcmds.o' is incompatible with i386:x86-64 output
...
I have installed ia32-libs and mutilib support. I think I just need to force the linker to generate a i386 output. I tried to put two ld flags in my gcc command as shown above: -melf_i386 and -oformat elf32-i386. But what happens is that gcc doesn't search for the 32 bit library in /usr/lib32 anymore. I wonder if I need to put those flags in some fixed order?
Thanks for any idea and help!
EDIT: when I add the -m32 flag in my last gcc command (the linking stage I believe), even if I have the -L/usr/lib32 flag in place, gcc doesn't search in /usr/lib32 anymore ( really weird...) and generates the following error:
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../libXaw.so when searching for -lXaw
/usr/bin/ld: skipping incompatible /usr/lib/libXaw.so when searching for -lXaw
/usr/bin/ld: cannot find -lXaw
collect2: ld returned 1 exit status
Any one has any idea why this happens? I am using the auto tool to configure and make. I am really good at modifying those script files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还需要使用带有
-m32
的链接。考虑到所有因素,我认为您应该能够在使用
-m32
时删除-L/usr/lib32
。You need to use link with
-m32
as well.All things considered, I think you should be able to drop the
-L/usr/lib32
when using-m32
.我解决了这个问题。我认为 gcc 正在期待一个静态库存档。我使用了 http://ubuntuforums.org/showthread 中的 getlibs 脚本。 php?t=474790 下载链接所需的所有 .a 档案。然后gcc工作了。我认为 gcc 确实在 /usr/lib32 目录中搜索,但没有找到 .a 档案,因此继续在标准目录中搜索这是/usr/lib,它在其中找到不兼容的*.so 文件。
但问题是:包 ia32-libs 中的 /usr/lib32/ 中的 *.so 文件实际上并没有这些库需要链接吗? /usr/lib32/ 中的这些文件有什么用?
I solved the problem. I think that gcc was expecting a static library archive. I used the getlibs script from http://ubuntuforums.org/showthread.php?t=474790 to download all the .a archives needed for linking. Then gcc worked. I think gcc did search in /usr/lib32 directory but didn't find the .a archives so went on to search in the standard directory which is /usr/lib, where it finds the incompatible *.so files.
But then the question is: the *.so files in /usr/lib32/ from package ia32-libs doesn't really have the libraries needed for linking? What are those files in /usr/lib32/ used for?