2011-06-07 204 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是什麼 - 一個變量或函數。