C语言 如何在 64 位 ubuntu 上安装 32 位 glibc
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23970684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install 32 bit glibc on 64 bit ubuntu
提问by Pratik Singhal
I am trying to learn the C Calling conventions in assembly language. To do so, I made a simple program using the putsfunction from the C standard library.
我正在尝试学习汇编语言中的 C 调用约定。为此,我使用putsC 标准库中的函数编写了一个简单的程序。
I assembled and linked the program with the following commands :-
我使用以下命令组装并链接了程序:-
nasm -f elf file.asmgcc -m32 file.asm -o file
nasm -f elf file.asmgcc -m32 file.asm -o file
The nasm produces the right object file but when running the gcc to link the object files, I am getting error.
Looking at the error I have figured it out that I don't have the 32 bit version of glibc on my system. How can I install it. I already have installed thispackage installed.
nasm 生成正确的目标文件,但是在运行 gcc 以链接目标文件时,出现错误。
查看错误后,我发现我的系统上没有 32 位版本的 glibc。我该如何安装它。我已经安装了这个包。
I have 64 bit ubuntu 12.04 as my OS.
我的操作系统是 64 位 ubuntu 12.04。
EDIT :- I have installed the following packages, but the problem is still not solved :-
编辑:-我已经安装了以下软件包,但问题仍未解决:-
1)ia32-libs
2) libc6-i386
1) ia32-libs
2) libc6-i386
回答by brennanhm
This command will install the 32bit glibc libraries on 64 bit Ubuntu:
此命令将在 64 位 Ubuntu 上安装 32 位 glibc 库:
sudo apt-get install gcc-multilib
This is the proper syntax for compiling assembly object code into an executable using gcc:
这是使用 gcc 将汇编目标代码编译为可执行文件的正确语法:
gcc -m32 objectfile.o -o executablefile
回答by Basile Starynkevitch
I assembled and linked the program with the following commands :-
nasm -f elf file.asmgcc -m32 file.asm -o file
我使用以下命令组装并链接了程序:-
nasm -f elf file.asmgcc -m32 file.asm -o file
This is wrong. Your first nasmcommand is probably creating a file.ofile (and you should check that, e.g. with ls -l file.o). The second gcccommand does not do what you wish.
这是错误的。您的第一个nasm命令可能是创建一个file.o文件(您应该检查它,例如使用ls -l file.o)。第二个gcc命令不会做你想要的。
But gccdoes not know about *.asmfile extensions (it knows about .Sfor preprocessable GNU assembler syntax, and .sfor assembler code, but probably handle unknown extensions like .asmas ELF object files by default, however file.asmis notan ELF object file). You should try linking with
但gcc不知道*.asm文件扩展名(它知道.S了preprocessable GNU汇编语法,并.s为汇编代码,但可能处理未知的扩展名如.asm由默认的ELF对象文件,不过file.asm是不是一个ELF目标文件)。你应该尝试链接
gcc -Wall -v -m32 file.o -o file
Notice that you give to GCCan objectfilein ELF(for the linkerinvoked by gcc) which you previously produced with nasm.
请注意,您在ELF 中向GCC 提供了一个目标文件(用于由调用的链接器),该文件是您之前使用.gccnasm
(you might later remove the -voption to gcc)
(您稍后可能会删除该-v选项gcc)
Alternatively, use the GNU asassembler syntax (not the nasmone), name your file file.S(if you want it to be preprocessed) or file.s(without preprocessing) and use gcc -v -Wall -m32 file.s -o myprogto compile it.
或者,使用 GNUas汇编器语法(不是nasm 语法),命名您的文件file.S(如果您希望对其进行预处理)或file.s(不进行预处理)并用于gcc -v -Wall -m32 file.s -o myprog编译它。
BTW, to understand more about calling conventions, read the x86-64 ABI spec(and the similar one for 32 bits x86 ...), make a small C example file some-example.c, then run gcc -S -fverbose-asm -O some-example.cand look into the produced some-example.swith an editor or pager.
顺便说一句,要了解有关调用约定的更多信息,请阅读x86-64 ABI 规范(以及类似的 32 位 x86规范...),制作一个小的 C 示例文件some-example.c,然后运行gcc -S -fverbose-asm -O some-example.c并some-example.s使用编辑器或寻呼机查看生成的内容。
Learn also more about ELFthen use readelf(& objdump) appropriately.
回答by Vlad
You want to install a package called 'ia32-libs'
你想安装一个名为“ia32-libs”的包

