使用makefile从lex文件生成a.out [英] generate a.out from lex file using makefile

查看:98
本文介绍了使用makefile从lex文件生成a.out的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有auto.lex,我想生成该文件的a.out.

I have auto.lex and I want to generate a.out of this file .

我尝试-

a.out: lex.yy.c
    gcc -c lex.yy.c

lex.yy.c: auto.lex
    flex -c auto.lex

但是它不起作用.

更改为-

a.out: lex.yy.c 
    gcc lex.yy.c 
lex.yy.c: auto.lex 
    flex auto.lex

并固定.

推荐答案

lex文件的推荐后缀为.l. GNU make具有内置规则.l.c,该规则可从lex源创建C代码.因此,如果要从auto.l创建可执行文件auto,则根本不需要Makefile.只需键入make auto:

The recommend suffix for lex files is .l. GNU make has a builtin rule .l.c that creates C code from a lex source. Thus, if you want to create an executable auto from auto.l, you don't need a makefile at all. Just type make auto:


$ make auto
lex  -t auto.l > auto.c
cc    -c -o auto.o auto.c
cc   auto.o  -lfl -o auto
rm auto.o auto.c

这篇关于使用makefile从lex文件生成a.out的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆