gcc - C程序编译错误

我正在尝试编译并安装一个1997年创建的程序。我正在使用gcc(GCC)4.1.2 20080704(Red Hat 4.1.2-50)和CentOS 5.5版(最终版)。在程序的SOURCE目录中尝试执行“make”命令时,出现以下错误:

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.版本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编程和makefile对我来说完全陌生,所以我真的不知道从哪里开始。我还可以提供任何其他信息来帮助调试此问题。

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);
    }
}

最佳答案

函数select_lines 中第84行错误

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

GCC不再允许在左侧进行强制转换。 C语言不允许这样做,并且gcc在遵循C规范方面变得越来越严格。

这就是为什么会产生此左值错误的原因。如果存在,您必须删除任何左 Actor 表。

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

像这样做,

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

https://stackoverflow.com/questions/6265380/

相关文章:

iphone - iOS启动画面导致问题

android - “Conversion to Dalvik format failed”错误不会

visual-studio-2010 - Visual Studio/TFS 2010/获取最新版本

java - 帮助通过 JSNI 调用传递复杂对象以绕过静态范围

matlab - Matlab mex中状态码2的构建错误

vb.net - 无法在Visual Studio中进行调试

c++ - C++ map : expected initializer before ‘<’ to

ios - 从GCC 4.2切换到LLVM 2.0时 ''中的 '-std='值无效

macos - 编译GLUT程序

c# - 如何从CMD(Shell)编译测试类和 Entity Framework Model.De