开发者

C program compiling error

I am trying to compile and install a program created in 1997. I am using gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-50) and CentOS release 5.5 (Final). While trying to do a 'make' command while in the SOURCE directory of the p开发者_Python百科rogram, I get the following error:

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

After initially considering this a c-code error, I tried to compile this on a Mac OSX 10.6.7 with i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664). This time I got an error a step after the original error implying that there is definitely an incompatibility with the gcc version in play. This time the error was:

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 programming and makefiles are completely alien to me so I really have no clue where to start. I can also provide any other information that will help in debugging this issue.

select_lines method defined in select.c is as follows:

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


There is an error in line no 84 in function select_lines

select.c: In function ‘select_lines’: select.c:84: error: invalid lvalue in increment

GCC no longer allows casts on the left side. The C language does not permit it, and gcc is becoming more strict about following the C spec.

Thats why this lvalue error is generated. You have to remove any left cast if present.

Perhaps, target = *((int *)lines)++; htis contains the error.

do it like this,

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


The only line that contains an increment that is dubious is:

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

You can reduce that to the following code:

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

The second assignment compiles - and correctly increments the value of the integer pointed at by the void pointer lines, assuming lines is appropriately initialized.

The doubly-defined symbol _Bos means that there are two files that define something called Bos in the source code. One is the file cass.o in the library libscol.a. The other is probably sents.c. You will have to make one or the other static, assuming they do the same thing. Or both static, unless there is some other file that uses the symbol. Or you may just need to change one declaration to extern. It depends a bit on what Bos is - a variable or a function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜