我正在学习Gnu通过“使用GNU Make管理项目”这本书。
我很不幸,我甚至无法在第1页的第5页中构建第一个传递示例。
操作系统: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 :(得分:0)
你忘了添加
#include <stdlib.h>
到count_words.c
答案 1 :(得分:0)
请参阅帖子:https://unix.stackexchange.com/questions/37971/usr-bin-ld-cannot-find-lfl
我尝试安装flex-static软件包,问题已修复。