2011-06-07 202 views
0

我试图编译和安装在1997年创建的程序。我使用gcc(GCC)4.1.2 20080704(Red Hat 4.1.2-50)和CentOS 5.5版(最终版)。虽然试图做一个“让”命令时,在程序的源目录,我得到以下错误:C程序编译错误

gcc -g -w -I/home/shahw/opinionfinder/software/scol1k/objs -I. -DDEBUG -DUNIX dump.c -L/home/shahw/opinionfinder/software/scol1k/objs -lscol -lm -o dump 
gcc -g -w -I/home/shahw/opinionfinder/software/scol1k/objs -I. -DDEBUG -DUNIX ngram.c -L/home/shahw/opinionfinder/software/scol1k/objs -lscol -lm -o ngram 
gcc -g -w -I/home/shahw/opinionfinder/software/scol1k/objs -I. -DDEBUG -DUNIX reg.c -L/home/shahw/opinionfinder/software/scol1k/objs -lscol -lm -o reg 
gcc -g -w -I/home/shahw/opinionfinder/software/scol1k/objs -I. -DDEBUG -DUNIX select.c -L/home/shahw/opinionfinder/software/scol1k/objs -lscol -lm -o select 
select.c: In function ‘select_lines’: 
select.c:84: error: invalid lvalue in increment 
make[1]: *** [select] Error 1 
make[1]: Leaving directory `/home/shahw/opinionfinder/software/scol1k/tools' 
make: *** [modules] Error 2 

开始考虑这样的C代码的错误后,我试图编译这个在Mac OSX 10.6.7与i686-apple-darwin10-gcc-4.2.1(GCC)4.2.1(Apple Inc. build 5664)。这次我在原始错误之后出现了一个错误,暗示着与游戏中的gcc版本存在不兼容性。这一次的错误是:

gcc -g -w -I/Users/shahjahanwarraich/Desktop/opinionfinderv1.5/software/scol1k/objs -I. -DDEBUG -DUNIX dump.c -L/Users/shahjahanwarraich/Desktop/opinionfinderv1.5/software/scol1k/objs -lscol -lm -o dump 
gcc -g -w -I/Users/shahjahanwarraich/Desktop/opinionfinderv1.5/software/scol1k/objs -I. -DDEBUG -DUNIX ngram.c -L/Users/shahjahanwarraich/Desktop/opinionfinderv1.5/software/scol1k/objs -lscol -lm -o ngram 
gcc -g -w -I/Users/shahjahanwarraich/Desktop/opinionfinderv1.5/software/scol1k/objs -I. -DDEBUG -DUNIX reg.c -L/Users/shahjahanwarraich/Desktop/opinionfinderv1.5/software/scol1k/objs -lscol -lm -o reg 
gcc -g -w -I/Users/shahjahanwarraich/Desktop/opinionfinderv1.5/software/scol1k/objs -I. -DDEBUG -DUNIX select.c -L/Users/shahjahanwarraich/Desktop/opinionfinderv1.5/software/scol1k/objs -lscol -lm -o select 
gcc -g -w -I/Users/shahjahanwarraich/Desktop/opinionfinderv1.5/software/scol1k/objs -I. -DDEBUG -DUNIX sents.c -L/Users/shahjahanwarraich/Desktop/opinionfinderv1.5/software/scol1k/objs -lscol -lm -o sents 
ld: duplicate symbol _Bos in /Users/shahjahanwarraich/Desktop/opinionfinderv1.5/software/scol1k/objs/libscol.a(cass.o) 
and /var/folders/F5/F5WuhlFlHcetJlreJ+GlMk+++TI/-Tmp-//ccjhIM0Y.o 
collect2: ld returned 1 exit status 
make[1]: *** [sents] Error 1 
make: *** [modules] Error 2 

C编程和makefiles是完全陌生的,所以我真的不知道从哪里开始。我还可以提供任何其他有助于调试此问题的信息。在select.c定义

select_lines方法如下:

select_lines (int type, void *lines, int n, FILE *infile, FILE *outfile) 
{ 
    char line[1024]; 
    int i, current = 0, target; 
    struct entry *e; 
    LinesA = make_aarray(SelectAlloc, sizeof(struct entry)); 

    /** Scan in the lines **/ 
    switch (type) { 

     case LINESFILE: 
    while (scan_int(target, lines) != EOF) { 
     new_line(target); 
    } 
    break; 

     case LINESLIST: 
    for (; n > 0; n--) { 
     target = *((int *)lines)++; 
     new_line(target); 
    } 
    break; 

     case LINESRANGE: 
    for (target = ((int *)lines)[0]; target <= ((int *)lines)[1]; target++) { 
     new_line(target); 
    } 
    break; 

     default: error("select_lines: Bad type"); 
    } 

    Lines = (struct entry *) LinesA->contents; 

    /** Sort by txt sequence **/ 
    qsort(Lines, NLines, sizeof(struct entry), txtcmp); 

    /** Extract lines **/ 
    current = -1; 
    for (i = 0; i < NLines; i++) { 
    target = Lines[i].txt; 
    if (target < current) error("sort failed"); 
    if (current < target) { /* careful: it's possible to select the same line twice */ 
     while (++current < target) { 
     skip_line(infile); 
     } 
     if (scan_line(line, 1024, infile) == EOF) { 
     fprintf(stderr, "Premature end of text file"); 
     exit(1); 
     } 
    } 
    Lines[i].line = copy_string(line); 
    } 

    /** Resort by smp sequence **/ 
    qsort(Lines, NLines, sizeof(struct entry), smpcmp); 

    /** Output **/ 
    for (i = 0; i < NLines; i++) { 
    fprintf(outfile, "%s\n", Lines[i].line); 
    } 
} 
+1

select.c的帖子行80-90 – 2011-06-07 12:52:41

+0

@William Pursell。问题已通过select_lines函数更新。谢谢。 – 2011-06-07 21:12:50

回答

0

存在错误在线在功能select_lines无84

select.c:在函数 'select_lines': select.c:84:错误:增量中的无效左值

GCC不再允许在左侧进行强制转换。 C语言不允许它,并且gcc对遵循C规范的要求越来越严格。

这就是为什么这个左值错误生成。如果存在,您必须移除任何左侧的投射。

也许,target = *((int *)lines)++; htis包含错误。

像这样做,

a1=(int *)lines; 
target=*a1++; 
0

包含一个增量的唯一行是可疑的是:

target = *((int *)lines)++; 

可以降低到下面的代码:

void select_lines(void *lines) 
{ 
    int target; 
    target = *((int *)lines) ++; // Error/warning 
    target = (*((int *)lines))++; // Clean 
} 

第二个任务编译 - 并正确增加void poin指向的整数的值ter lines,假设lines被适当地初始化。

双重定义的符号_Bos表示在源代码中有两个文件定义了Bos。一个是库libscol.a中的文件cass.o。另一个可能是sents.c。假设他们做同样的事情,你将不得不做出一个或另一个静态。或者都是静态的,除非有其他文件使用该符号。或者您可能只需要将一个声明更改为extern。这取决于Bos是什么 - 一个变量或函数。