2014-11-22 56 views
0

我正在研究Gnu通過書「使用GNU Make管理項目」。make:***沒有規則來製作`count_words'所需的'-lfl'。停止

我很不幸,我甚至不能建立通過網頁的第一個例子:章5 1.

OS:CentOS7

這裏是代碼:

/* count_words.c */ 
#include <stdio.h> 

extern int fee_count, fie_count, foe_count, fum_count; 
extern int yylex(void); 

int main(int argc, char **argv) 
{ 
    yylex(); 
    printf("%d %d %d %d\n", fee_count, fie_count, foe_count, fum_count); 
    exit(0); 
} 

lexer.l

int fee_count = 0; 
    int fie_count = 0; 
    int foe_count = 0; 
    int fum_count = 0; 
%% 
fee fee_count++; 
fie fie_count++; 
foe foe_count++; 
fum fum_count++; 


#makefile 
count_words: count_words.o lexer.o -lfl 
    gcc count_words.o lexer.o -lfl -o count_words 

count_words.o: count_words.c 
    gcc -c count_words.c 

lexer.o: lexer.c 
    gcc -c lexer.c 

lexer.c: lexer.l 
    flex -t lexer.l > lexer.c 

clean: 
    rm *.o lexer.c 

構建錯誤提示是:

gcc -c count_words.c 
count_words.c: In function ‘main’: 
count_words.c:11:2: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default] 
    exit(0); 
^ 
flex -t lexer.l > lexer.c 
gcc -c lexer.c 
make: *** No rule to make target `-lfl', needed by `count_words'. Stop. 

當我從count_words先決條件刪除-lfl,它與錯誤建太多:

gcc -c count_words.c 
count_words.c: In function ‘main’: 
count_words.c:11:2: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default] 
    exit(0); 
^ 
flex -t lexer.l > lexer.c 
gcc -c lexer.c 
gcc count_words.o lexer.o -lfl -o count_words 
/bin/ld: cannot find -lfl 
collect2: error: ld returned 1 exit status 
make: *** [count_words] Error 1 

我會搜索網絡,但沒有發現任何有用的。

非常感謝。

回答

0

你忘記

#include <stdlib.h> 

添加到count_words.c

+0

非常感謝。剛纔我用下面的鏈接修復它。不管怎樣,謝謝你。 – Amitabha 2014-11-22 23:34:10

相關問題