朋友,
我正在尝试通过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]
但是,当我尝试通过autotools创建它时,它给出了问题:
##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的长输出,这样对于一些有经验的人来说可能会有所帮助。 期待您的帮助。
答案 0 :(得分:0)
啊......解决。
bison -d foo.y
通常会foo.tab.h
;
对于automake,它正在制作foo.h
。
解决
答案 1 :(得分:0)
古代Automakes中存在一些已知问题,包括您描述的问题。你肯定应该升级到1.13。