tags:

views:

317

answers:

2

On my machine (Windows running cygwin) it compiles correctly. Flex is version 2.5.35 and bison is version 2.3

On linux machine 1 it compiles correctly. Flex is version 2.5.4 and bison is version 1.875c.

On linux machine 2 it does not compile correctly. Flex is version 2.5.4 and bison is 2.3.

One would expect by looking at the flex/bison version numbers that if it compiled correctly on my machine, it would compile correctly on machine 2, but that's not the case.

On linux machine 2, when I run gcc -c y.tab.c I get the following warnings several times

warning: incompatible implicit declaration of built-in function 'printf'

And when I run the following

gcc -o cminus y.tab.o lex.yy.o -ly -lfl

I get the following error.

gcc -o cminus y.tab.o lex.yy.o -ly -lfl
/usr/bin/ld: cannot find -ly
collect2: ld returned 1 exit status
make: *** [cminus] Error 1

This error can be removed by taking out the -ly option in gcc so that the program compiles, but the compiled program does not function correctly as it does on my machine and the other linux machine.

What could be causing the problem?

+2  A: 
/usr/bin/ld: cannot find -ly

is the message you get when the linker cannot find the library.

You need to locate liby.a or liby.so and then insert a -L<that path> in your gcc command line.

On my Cygwin install, it's located in /lib/liby.a.

paxdiablo
A: 

The warning sounds like you have a missing '#include ' in some source file. The link error means that you don't have liby.a installed on your machine. liby is part of yacc and some versions of bison, but is rarely actually needed (it just defines default implementations of yyerror and a couple other things). The fact that it links without it means that you don't really need it.

You don't say in what way the progrma misbehaves when its not functioning correctly, so that's tough to diagnose

Chris Dodd
The missing #include is for <stdio.h>
quark
Yeah, for some reason stackoverflow doesn't show the <stdio.h> in the quotes in my answer
Chris Dodd