2014-02-17 82 views
2

我有rfact.s和rfactmain.c如何鏈接兩個目標文件

rfact.s:

.text 
.p2align 4 
.global rfact 
.type rfact, @function 

rfact: 
pushl %ebp 
movl %esp, %ebp 
pushl %ebx 
subl $4, %esp 
movl 8(%ebp), %ebx 
movl $1, %eax 
cmpl $1, %ebx 
jle  .L53 

leal -1(%ebx), %eax 
movl %eax, (%esp) 
call rfact 
imull %ebx, %eax 


.L53: 
addl $4, %esp 
popl %ebx 
popl %ebp 
ret 

rfactmain.c:

int main(){ 
    int x = rfact(4); 
    return 0; 
} 

我是一個64位系統。因此,首先我做

gcc -m32 -c rfact.s 
gcc -m32 -c rfactmain.c 

同時獲得目標文件,然後我試圖把它們像這樣

gcc -m32 -o rf rfact.o rfactmain.o 

聯繫在一起,但我得到一個錯誤

gcc -m32 -o rf rfact.o rfactmain.o 
/usr/bin/ld: cannot find crt1.o: No such file or directory 
/usr/bin/ld: cannot find crti.o: No such file or directory 
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.2/libgcc_s.so when searching for -lgcc_s 
/usr/bin/ld: cannot find -lgcc_s 
/usr/bin/ld: skipping incompatible /usr/lib64/libc.so when searching for -lc 
/usr/bin/ld: skipping incompatible /usr/lib64/libc.a when searching for -lc 
/usr/bin/ld: cannot find -lc 
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.2/libgcc_s.so when searching for -lgcc_s 
/usr/bin/ld: cannot find -lgcc_s 
/usr/bin/ld: cannot find crtn.o: No such file or directory 
collect2: error: ld returned 1 exit status 

如果我刪除-m32我得到錯誤(這是預期的,因爲兩個目標文件都是32位)

gcc -o rf rfact.o rfactmain.o 
/usr/bin/ld: i386 architecture of input file `rfact.o' is incompatible with i386:x86-64 output 
/usr/bin/ld: i386 architecture of input file `rfactmain.o' is incompatible with i386:x86-64 output 
collect2: error: ld returned 1 exit status 

回答

1

您沒有安裝32位支持。您可能需要分別使用gcc-multilib軟件包或32位庫軟件包。請諮詢您的發行人文件和/或包裹經理。