昨天我的朋友和我建立了我们的开发环境,开始完成学校作业。我们的教授给了我们一些汇编代码来编译和链接我们自己的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();
}
答案 0 :(得分:3)
int prints(chars *s)
^ looks bad