From: Keith M. <kei...@us...> - 2013-01-03 20:29:36
|
On 03/01/13 07:24, Stephen Grant Brown wrote: > All I want is the makefile so I can execute lnc.exe fom the following > lnc.flex file which is an examlpe in flex.info. Okay, but I'd suggest that you should also want to understand why you got it wrong, in the first instance. > $ less lnc.flex > int num_lines = 0, num_chars = 0; > > %% > \n ++num_lines; ++num_chars; > . ++num_chars; > > %% > main() > { > yylex(); > printf( "# of lines = %d, # of chars = %d\n", > num_lines, num_chars ); > } As written, this will require libfl.a; that could be a problem, because I don't think we provide a mingw32 compatible version right now, and you CANNOT use the MSYS version. This library provides only two functions: yywrap(), (which yylex() will call when it exhausts its input stream), and a default main(). You've already provided your own main(), within your lnc.flex -- by convention, this should be lnc.l -- so all you need from libfl.a is yywrap(). Now, it is intended that users should provide their own yywrap(); its purpose is to allow you to attach a new data source to the input stream, before returning zero, to instruct yylex() to continue scanning; (there are other, arguably better, ways to achieve this). If you don't need this capability, then you have three options: 1) Add '%option noyywrap', (without the quotes), to the first section of lnc.l; (before the first '%%' section break -- as the first line should suffice). 2) Add your own yywrap() implementation to the third section of lnc.l; the default implementation, as provided by libfl.a, is as simple as: int yywrap(){ return 1; } so adding this, as the last line of lnc.l, would suffice. 3) Build your own mingw32 compatible libfl.a, and save it within your /mingw/lib directory; the yywrap() implementation is as shown for option (2), and main() is: int main () { while (yylex() != 0) ; return 0; } Of these, my personal preference would be option (1). Now, to correct your makefile: if you choose either option (1) or option (2), you can simply remove all references to libfl.a, because you don't need it at all; if you choose option (3), then you DO need libfl.a, but you need to correct your references to it. In a previous post, I've already explained why your current usage is wrong; the correct form of reference is simply '-lfl' (again, without the quotes), and if you've saved it in any non-standard path, you may also need to precede that with a '-L /path/to/library' specification, so gcc knows where to look for it; see http://mingw.org/wiki/IncludePathHOWTO for further details. > I will just use the MSYS flex. That's fine for compiling the flex code, but the caveat is that you cannot use its accompanying libfl.a, because it isn't compatible with the mingw32 compiler; you must either eliminate dependencies on libfl.a from your flex sources, or you must furnish a mingw32 compatible version of this library. > I am sorry I got into things above my level of understanding No need to apologise; this is how we raise our level of understanding. -- Regards, Keith. |