Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've written this code just to learn how to use gas assembler:

.code32

.section .data
    values:
    .int 1,2,3,4,5,6,7,8,9
    output:
    .asciz "current value %d"
    
.section .text
    .globl _start
    _start:
    movl $10, %edi
    loop:
    movl values(,%edi,4),%eax
    pushl %eax
    pushl $output
    call printf
    addl $8, %esp
    dec %edi
    jnz loop
    pushl $0
    call exit


It uses two C lib functions (printf and exit). I'm on x64, but this code is 32bit, so I assembled using this command:

as --32 -o test.o test.asm

It looks like it produce a valid obj file. The problem is that I'm not able to link this file...
I use this command:

ld -dynamic-linker /lib/ld-linux.so.2 -lc -o test test.o

but it says that the arch is not compatible, so I've tried:

ld -dynamic-linker /lib/ld-linker.so.2 -lc -o test test.o -melf_i386

but then it says:
ld: skipping /usr/lib64/libc.so not compatible -lc


How should I link that obj file ? Many thanks for the help!
Posted

1 solution

You cannot link a 32-bit object with a 64-bit library, the two are not compatible.
 
Share this answer
 
Comments
Luca D'Amico 25-Aug-14 14:00pm    
I know, how can I tell to the linker to use the 32-bit libs ? Thanks
Richard MacCutchan 26-Aug-14 2:40am    
Ensure that your library search path only contains the directories where the 32-bit libraries are located.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900