32

I'm trying to build gcc 4.6, but I'm getting some linker errors that look like it means bison or flex isn't getting linked to. When the makefile issues this command:

gcc   -g -fkeep-inline-functions -DIN_GCC   -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Wold-style-definition -Wc++-compat -fno-common  -DHAVE_CONFIG_H -DGENERATOR_FILE  -o build/gengtype \
        build/gengtype.o build/errors.o build/gengtype-lex.o build/gengtype-parse.o build/version.o ../../build-x86_64-unknown-linux-gnu/libiberty/libiberty.a

It tells me:

/home/chris/code/gcc/trunk/host-x86_64-unknown-linux-gnu/gcc/../.././gcc/gengtype.c:960: undefined reference to `lexer_line'
... undefined reference to `yylex'
... undefined reference to `yybegin'
... undefined reference to `yyend'

I've installed Flex and Bison, and even tried several Bison variants with the same result. Does anybody know what else this might mean?

Chris
  • 6,594
  • 7
  • 40
  • 54
  • Which versions of flex, bison and other tools have you used? Was the same error occurring at every such attempt? Some old discussions that Google finds for _gengtype.c undefined reference to `lexer_line' ... undefined reference to `yylex'_ points to a possible problem with flex. Are you building from the svn trunk? Or from some distribution's source repository? – vpit3833 Nov 24 '10 at 06:16
  • The same happened to me. Is this some kind of bug that first itme installation will not work properly? – Aman Deep Gautam Jun 30 '12 at 01:42

3 Answers3

49

Same happened to me, it was due to lack of flex and bison. After installing flex and bison, I ran make distclean and ./configure, then it compiled fine.

Ross Rogers
  • 22,451
  • 24
  • 104
  • 161
Ricbit
  • 779
  • 7
  • 15
  • 7
    Aha, make *distclean*. I'd tried just a `make clean`, but that didn't work. I was about to try nuking from orbit like @Chris suggested, but this worked just as well. – Adam Rosenfield Mar 18 '11 at 15:09
  • For the record this was the fix for a standard Ubuntu install (11.04) – Hooked Aug 30 '11 at 14:27
  • 3
    The gcc installation docs recommend not running configure in the source dir. If you run ../gcc-srcdir/configure from a different dir then the source dir remains untouched and you can just remove the whole obj dir. That is more reliable (and faster) than "make distclean" – Jonathan Wakely Dec 08 '13 at 14:54
  • 2
    Why does configure not warn about the lack of flex? It [was so picky with GMP!](http://stackoverflow.com/questions/9253695/building-gcc-requires-gmp-4-2-mpfr-2-3-1-and-mpc-0-8-0) – Ciro Santilli Путлер Капут 六四事 May 13 '15 at 10:12
3

Ran into this as well but the fix for me was to install bisonc++, for whatever reason I only had bison installed.

Justin Buser
  • 2,805
  • 24
  • 32
1

It just got into some weird state since I did ./configure and tried to build it before having bison and flex set up properly. Calling make clean wasn't enough. I wiped out the whole thing and did a fresh checkout and it builds fine now.

Chris
  • 6,594
  • 7
  • 40
  • 54