c - 使用 makefile 从 lex 文件生成 a.out

标签 c makefile lex flex-lexer

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

我试过了-

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:

$ 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

关于c - 使用 makefile 从 lex 文件生成 a.out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13165681/

相关文章:

c - Lex/Flex - 拆分电话号码?

用 libtasn1.h 编译 c

c++ - C 与 C++ 函数问题

linux - 如何强制配置脚本生成发布makefile

c - 编译 lex 生成的文件时 errno.h(以及更多)中出现错误

c++ - 简单的 Flex/Bison C++

c - 无法通过读取 x、y 坐标输入到数组来计算多边形的周长

c - 将我的程序的 stderr 重定向到 config.log

linker - 使用 g++ 链接无法搜索 -lstdc++

linux - 为疯狂的大软件制作 .spec 文件的理智方法