2013-08-27 46 views
0

昨天我和朋友建立了我們的開發環境,開始做一個學校作業。我們的教授給了我們一些彙編代碼來編譯和鏈接我們自己的C代碼來替換一個linux booter程序。但是,由於某些原因,代碼會在我的朋友機器上完全編譯,但是會給我一些編譯錯誤。這個代碼是由教授給出的,所以我知道它一定是正確的。我們檢查了我們的密件抄送版本,它們是相同的。以下是錯誤輸出:編譯與密件抄送兼容性問題

comiling ...... 
main.c:17.5: error: need '{' 
main.c:17.7: error: chars undeclared 
main.c:19.12: error: illegal indirection 
main.c:20.15: error: illegal indirection 
main.c:25.4: error: bad expression 
main.c:25.10: error: need ';' 
main.c:25.15: error: blk undeclared 
main.c:25.19: error: buf undeclared 
main.c:25.3: error: need ';' 
main.c:25.4: error: bad expression 
main.c:25.7: error: need ';' 
main.c:25.4: error: bad expression 
main.c:30.4: error: bad expression 
main.c:30.9: error: need ';' 
main.c:30.10: error: temp undeclared 
main.c:30.14: error: illegal indirection 
main.c:33.1: error: need ';' 
main.c:eof: error: need '}' 
linking ....... 
ld86: cannot open input file main.o 
check a.out size 
ls: cannot access a.out: No such file or directory 
dump a.out to a VIRTUAL FD 
dd: opening ‘a.out’: No such file or directory 

這就是用這個shell腳本生成的:

#!/bin/bash 

echo comiling ...... 
as86 -o bs.o bs.s 
bcc -c -ansi main.c 

echo linking ....... 
ld86 -d bs.o main.o /usr/lib/bcc/libc.a 
echo check a.out size 
ls -l a.out 

echo dump a.out to a VIRTUAL FD 
dd if=a.out of=mtximage.bin bs=1024 count=1 conv=notrunc 

最後這裏是main.c中,它是在編譯錯誤:

/******************************************************* 
*     @main.c file       * 
*******************************************************/ 
typedef unsigned char u8; 
typedef unsigned short u16; 
typedef unsigned long u32; 

#include "ext2.h" 
typedef struct ext2_group_desc GD; 
typedef struct ext2_inode  INODE; 
typedef struct ext2_dir_entry_2 DIR; 

#define BLK 1024 

char buf1[BLK], buf2[BLK]; 

int prints(chars *s) 
{ 
    while(*s) 
    putc(*s++); 


} 

u16 getblk(u16 blk, char *buf) 
{ 
    readfd(blk/18, ((blk*2)%36)/18, ((blk*2)%36)%18, buf); 
} 

char temp[256]; 

main() 
{ 
    u16 i,iblk; 
    char c; 
    GD *gp; 
    INODE *ip; 
    DIR *dp; 

    prints("read decsriptor block #2 into buf1[]\n\r"); 
    getblk(2, buf1); 
    gp = (GD *)buf1; 
    iblk = (u16)gp->bg_inode_table; 
    prints("inodes blk = "); putc(iblk + '0'); prints("\n\r"); 

    getblk((u16)iblk, buf1); // read first inode block block 
    ip = (INODE *)buf1 + 1; // ip->root inode #2 

    prints("read 0th data block of root inode into buf2[ ]\n\r"); 

    getblk((u16)ip->i_block[0], buf2); 
    dp = (DIR *)buf2;   // buf2 contains DIR entries 

    while((char *)dp < &buf2[BLK]){ 



    c = dp->name[dp->name_len]; 
    dp->name[dp->name_len] = 0; 
    prints(dp->name); putc(' '); 
    dp->name[dp->name_len] = c; 

    dp = (DIR *)((char *)dp + dp->rec_len); 
    } 

    prints("\n\rgo?"); getc(); 
} 

回答

3
int prints(chars *s) 

      ^looks bad 
+1

+1,而且我不相信OP的好友機器上的「相同的代碼會完全編譯好」。 –

+0

哈哈我剛剛在我的代碼中看到了這個,並且正要回答我自己的問題..哈哈謝謝 –