野牛中的自动制作,可与手写的makefile一起正常工作
Posted
技术标签:
【中文标题】野牛中的自动制作,可与手写的makefile一起正常工作【英文标题】:automake-ing in bison which works fine with handwritten makefile 【发布时间】:2013-04-25 09:44:13 【问题描述】:朋友们,
我正在尝试通过 gnu-autotools 为 flex+bison+C 代码创建 Makefile(你可以说是玩具代码)。手写的 Makefile 工作正常
CC=gcc #-g -Wall
FLEX=flex
BISON=bison
LIBS=lfl
PROG=parse
$PROG:bib.y scan.l main.c
$BISON -d bib.y
$FLEX -i scan.l
$CC -Wall main.c lex.yy.c bib.tab.c `pkg-config --cflags --libs gtk+-3.0 glib-2.0` -$LIBS -o $@
clean:
rm -f lex.yy.c bib.tab.h $PROG bib.tab.c
touch scan.l bib.y main.c
只对未使用的变量发出警告:
$ make -f MAKEFILE
bison -d bib.y
flex -i scan.l
gcc -Wall main.c lex.yy.c bib.tab.c `pkg-config --cflags --libs gtk+-3.0 glib-2.0` -lfl -o parse
main.c: In function ‘main’:
main.c:35:8: warning: type defaults to ‘int’ in declaration of ‘yy_create_buffer’ [-Wimplicit-int]
main.c:35:8: warning: unused variable ‘yy_create_buffer’ [-Wunused-variable]
lex.yy.c:1120:17: warning: ‘yyunput’ defined but not used [-Wunused-function]
lex.yy.c:1161:16: warning: ‘input’ defined but not used [-Wunused-function]
bib.y: In function ‘parse_entry’:
bib.y:79:9: warning: unused variable ‘author’ [-Wunused-variable]
但是,当我尝试通过自动工具创建它时,它给出了问题:
##Configure.ac (made mostly with autoscan)
AC_PREREQ([2.69])
AC_INIT([Bi-Try],[1.0],[rudra.banerjee@aol.co.uk])
AM_INIT_AUTOMAKE([1.9.6])
# Checks for programs.
AC_PROG_CC
AC_PROG_YACC
AC_PROG_LEX
# Checks for libraries.
#AC_PROG_LIBTOOL
# Checks for header files.
# Checks for library functions.
AM_PATH_GTK_3_0([3.4.0],,AC_MSG_ERROR([Gtk+ 3.0.0 or higher required.]))
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
还有makefile.am
bin_PROGRAMS = bitry
bitry_SOURCES = bib.y scan.l main.c
AM_YFLAGS = -d
AM_LFLAGS = -i
bitry_LDADD = @GTK_LIBS@ @LEXLIB@
AM_CFLAGS = @GTK_CFLAGS@
过程的输出是:
$ autoreconf --install Makefile.am: 安装 './INSTALL' Makefile.am:使用 GNU 通用公共许可证安装“./COPYING” v3 文件 Makefile.am:考虑将 COPYING 文件添加到 版本控制系统 Makefile.am:为您的代码,避免 关于您的项目使用哪种许可证的问题
$ ./configure -q
$ make -s
scan.o: In function `yy_get_previous_state':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1070: multiple definition of `yyin'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1070: first defined here
scan.o: In function `yy_switch_to_buffer':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1254: multiple definition of `yy_switch_to_buffer'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1254: first defined here
scan.o: In function `yy_delete_buffer':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1329: multiple definition of `yy_delete_buffer'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1329: first defined here
scan.o: In function `yy_flush_buffer':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1375: multiple definition of `yy_flush_buffer'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1375: first defined here
scan.o: In function `yy_create_buffer':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1299: multiple definition of `yy_create_buffer'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1299: first defined here
scan.o: In function `yyrestart':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1237: multiple definition of `yyrestart'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1237: first defined here
scan.o: In function `yylex':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:663: multiple definition of `yylex'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:663: first defined here
scan.o: In function `yy_get_previous_state':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1072: multiple definition of `yyout'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1072: first defined here
scan.o: In function `yypush_buffer_state':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1404: multiple definition of `yypush_buffer_state'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1404: first defined here
scan.o: In function `yypop_buffer_state':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1433: multiple definition of `yypop_buffer_state'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1433: first defined here
scan.o: In function `yy_scan_buffer':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1501: multiple definition of `yy_scan_buffer'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1501: first defined here
scan.o: In function `yy_scan_bytes':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1551: multiple definition of `yy_scan_bytes'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1551: first defined here
scan.o: In function `yy_scan_string':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1538: multiple definition of `yy_scan_string'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1538: first defined here
scan.o: In function `yyget_lineno':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1616: multiple definition of `yyget_lineno'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1616: first defined here
scan.o:(.data+0x0): multiple definition of `yylineno'
bib.o:(.data+0x0): first defined here
scan.o: In function `yyget_in':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1624: multiple definition of `yyget_in'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1624: first defined here
scan.o: In function `yyget_out':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1632: multiple definition of `yyget_out'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1632: first defined here
scan.o: In function `yyget_leng':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1640: multiple definition of `yyget_leng'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1640: first defined here
scan.o: In function `yyget_text':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1649: multiple definition of `yyget_text'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1649: first defined here
scan.o: In function `yyset_lineno':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1658: multiple definition of `yyset_lineno'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1658: first defined here
scan.o: In function `yyset_in':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1669: multiple definition of `yyset_in'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1669: first defined here
scan.o: In function `yyset_out':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1674: multiple definition of `yyset_out'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1674: first defined here
scan.o: In function `yyget_debug':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1680: multiple definition of `yyget_debug'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1680: first defined here
scan.o: In function `yy_get_previous_state':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1066: multiple definition of `yy_flex_debug'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1066: first defined here
scan.o: In function `yyset_debug':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1684: multiple definition of `yyset_debug'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1684: first defined here
scan.o: In function `yylex_destroy':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1717: multiple definition of `yylex_destroy'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1717: first defined here
scan.o: In function `yyalloc':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1763: multiple definition of `yyalloc'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1763: first defined here
scan.o: In function `yyrealloc':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1775: multiple definition of `yyrealloc'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1775: first defined here
scan.o: In function `yyfree':
/home/rudra/Programs/lex/Parsing/ruda/scan.c:1780: multiple definition of `yyfree'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.c:1780: first defined here
scan.o: In function `yywrap':
/home/rudra/Programs/lex/Parsing/ruda/scan.l:16: multiple definition of `yywrap'
bib.o:/home/rudra/Programs/lex/Parsing/ruda/bib.l:16: first defined here
main.o: In function `main':
/home/rudra/Programs/lex/Parsing/ruda/main.c:36: undefined reference to `setup_tree'
/home/rudra/Programs/lex/Parsing/ruda/main.c:44: undefined reference to `yyparse'
bib.o: In function `yylex':
bib.c:(.text+0x7c1): undefined reference to `yylval'
bib.c:(.text+0x84b): undefined reference to `yylval'
bib.c:(.text+0x872): undefined reference to `yylval'
scan.o: In function `yylex':
scan.c:(.text+0x7c1): undefined reference to `yylval'
scan.c:(.text+0x84b): undefined reference to `yylval'
scan.o:scan.c:(.text+0x872): more undefined references to `yylval' follow
collect2: error: ld returned 1 exit status
make: *** [bitry] Error 1
我发布了 makefile 的长输出,以便对一些有经验的人有所帮助。 期待您的帮助。
【问题讨论】:
标记时要小心。 Flex 用于 Adobe/Apache UI 框架。 gnu-flex 用于词法分析器。 【参考方案1】:啊...解决了。
bison -d foo.y
一般是foo.tab.h
;
对于automake,它的制作foo.h
。
解决了
【讨论】:
【参考方案2】:古代 Automakes 中有几个已知问题,包括您所描述的问题。例如,您绝对应该升级到 1.13。
【讨论】:
以上是关于野牛中的自动制作,可与手写的makefile一起正常工作的主要内容,如果未能解决你的问题,请参考以下文章
required_once() 中的变量未定义但可与 require() 一起使用,为啥?
Linux下automake工具使用(自动构建Makefile文件)
JavaFX UI 在事件侦听器中的 JavaFX 应用程序线程中冻结,但可与 Platform.runLater 一起使用