How to install 32 bit glibc on 64 bit ubuntu

41,017

Solution 1

This command will install the 32bit glibc libraries on 64 bit Ubuntu:

sudo apt-get install gcc-multilib

This is the proper syntax for linking assembly object code into an executable using gcc:

gcc -m32 objectfile.o -o executablefile

(nasm -felf32 already creates objectfile.o; the .asm file should not appear on GCC's command line. GCC can assemble+link a .S file in one step using GAS syntax, but NASM is a separate package.)

Solution 2

I assembled and linked the program with the following commands :- nasm -f elf file.asm gcc -m32 file.asm -o file

This is wrong. Your first nasm command is probably creating a file.o file (and you should check that, e.g. with ls -l file.o). The second gcc command does not do what you wish.

But gcc does not know about *.asm file extensions (it knows about .S for preprocessable GNU assembler syntax, and .s for assembler code, but probably handle unknown extensions like .asm as ELF object files by default, however file.asm is not an ELF object file). You should try linking with

gcc -Wall -v -m32 file.o -o file

Notice that you give to GCC an object file in ELF (for the linker invoked by gcc) which you previously produced with nasm.

(you might later remove the -v option to gcc)

Alternatively, use the GNU as assembler syntax (not the nasm one), 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 myprog to compile it.

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.c and look into the produced some-example.s with an editor or pager.

Learn also more about ELF then use readelf (& objdump) appropriately.

Share:
41,017
Pratik Singhal
Author by

Pratik Singhal

Hi, I am currently working as a software development engineer at Amazon India. I am a fullstack developer and have lot of experience in developing end to end applications (mobile app, web app and backend) for multiple different projects.

Updated on January 18, 2021

Comments

  • Pratik Singhal
    Pratik Singhal over 3 years

    I am trying to learn the C Calling conventions in assembly language. To do so, I made a simple program using the puts function from the C standard library.

    I assembled and linked the program with the following commands :-

    nasm -f elf file.asm gcc -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 this package installed.

    I have 64 bit ubuntu 12.04 as my OS.

    EDIT :- I have installed the following packages, but the problem is still not solved :-

    1)ia32-libs
    2) libc6-i386

  • Leb
    Leb over 8 years
    @BasileStarynkevitch Then there must be an explanation as to why. Posting code only does not teach anything
  • Admin
    Admin over 8 years
    Thanks for the feedback. I've elaborated a bit on my answer. I simply wanted to share the command I used to get the 32bit glibc libraries.
  • Gauthier
    Gauthier over 5 years
    This helped me cross-compile for ARM on a x64 with debien, with arm-none-eabi-gcc from 2015q2.