Problem with linking multiple flex-Scanners

Problem with linking multiple flex-Scanners

Post by Stephan Kuhage » Tue, 04 Dec 2001 17:54:32



Hello

I have a problem with linking multiple flex-scanners into one
binary. I am using Linux with different versions of gcc (c++) and flex
version 2.5.4. When trying to link both scanner into one binary, I get
multiple definitions of hundreds of things. When trying to use the
-Pprefix-Flag, I get redefinition of `class netFlexLexer` or whatever
I use for the prefix. Using namespaces around the scanners also does
not work.

Has anybody a solution for this problem? Any help will be
appreciated. Thanks!

Stephan Kuhagen
--
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\

| >>> ...destination anywhere,          -\<,    |
| >>> east or west, I don't care...   (*)/(*)   |
| WWW:   http://www.tzi.de/~stk                 |
\_______________________________________________/

PS: Ich widerspreche der Nutzung oder Uebermittlung meiner
Daten fuer Werbezwecke oder fuer die Markt- und Meinungsforschung

(28 Abs. 3 Bundesdatenschutzgesetz)

 
 
 

Problem with linking multiple flex-Scanners

Post by Andreas Baue » Tue, 04 Dec 2001 19:46:03


Quote:> I have a problem with linking multiple flex-scanners into one
> binary. I am using Linux with different versions of gcc (c++) and flex
> version 2.5.4. When trying to link both scanner into one binary, I get
> multiple definitions of hundreds of things. When trying to use the
> -Pprefix-Flag, I get redefinition of `class netFlexLexer` or whatever
> I use for the prefix. Using namespaces around the scanners also does
> not work.

Use -P individually for each and every class that flex generates and read
the man page of flex:

       If you want to create multiple (different) lexer  classes,
       you use the -P flag (or the prefix= option) to rename each
       yyFlexLexer to  some  other  xxFlexLexer.   You  then  can
       include <FlexLexer.h> in your other sources once per lexer
       class, first renaming yyFlexLexer as follows

If that doesn't help you, you should consider posting the exact error
messages of your linker. Some flex versions just *on unistd.h stuff
and then a simple software upgrade would fix your problems (that is, if
you use an affected Linux distribution, such as RedHat 7.0 for example)

And no, cross-posting still isn't fashionable.

--
Andreas Bauer, baueran at in.tum.de
http://www.veryComputer.com/

 
 
 

Problem with linking multiple flex-Scanners

Post by Stephan Kuhage » Tue, 04 Dec 2001 23:54:43



> Use -P individually for each and every class that flex generates and read
> the man page of flex:

>        If you want to create multiple (different) lexer  classes,
>        you use the -P flag (or the prefix= option) to rename each
>        yyFlexLexer to  some  other  xxFlexLexer.   You  then  can
>        include <FlexLexer.h> in your other sources once per lexer
>        class, first renaming yyFlexLexer as follows

> If that doesn't help you, you should consider posting the exact error
> messages of your linker. Some flex versions just *on unistd.h stuff
> and then a simple software upgrade would fix your problems (that is, if
> you use an affected Linux distribution, such as RedHat 7.0 for example)

Thanks for the help, but... does not work. I read the man page. Maybe
I am too stupid to understand it... I made a small example, that may
show the problem:

This is the class-include:

---------------------- my scanner class: scan_a.hh ---------------------
#ifndef scan_a
#define scan_a

#undef yyFlexLexer
#define yyFlexLexer a_FlexLexer
#include <FlexLexer.h>

class scana : public a_FlexLexer {
public:
    scana();
private:
    int yylex();

Quote:};

#endif
------------------------------------------------------------------------

and this is the flex-file:

----------------------- my flex file: scan_a.hh ------------------------
%option c++
%option yyclass="scana"

%{
#include <iostream>
#include "scan_a.hh"
%}

%%
<*>. {
    cout << "scan a: " << YYText() << endl;

Quote:}

%%
------------------------------------------------------------------------

Then

flex -+ -8 -Pa_ scan_a.lex

which works fine, and then

c++ lex.a_.cc

which says

In file included from scan_a.hh:6,
                 from scan_a.lex:6:
/usr/include/FlexLexer.h:103: redefinition of `class a_FlexLexer'
/usr/include/FlexLexer.h:103: previous definition here
/usr/include/FlexLexer.h:184: confused by earlier errors, bailing out

But of course in FlexLexer.h is no class a_FlexLexer defined. If I
omit the undef-define-pair in the class-file, it produces the same
error. So, the problem is, that I am not able to rename the
Lexer-Class and methods.

Thanks
Stephan Kuhagen

--
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\

| >>> ...destination anywhere,          -\<,    |
| >>> east or west, I don't care...   (*)/(*)   |
| WWW:   http://www.veryComputer.com/~stk                 |
\_______________________________________________/

PS: Ich widerspreche der Nutzung oder Uebermittlung meiner
Daten fuer Werbezwecke oder fuer die Markt- und Meinungsforschung

(28 Abs. 3 Bundesdatenschutzgesetz)

 
 
 

Problem with linking multiple flex-Scanners

Post by Scott Smit » Thu, 06 Dec 2001 15:35:06




> #include <FlexLexer.h>

Leave this out.

--

   "Nullus Anxietas"

 
 
 

Problem with linking multiple flex-Scanners

Post by Stephan Kuhage » Thu, 06 Dec 2001 20:54:30





> > #include <FlexLexer.h>

> Leave this out.

Well, sure, I can now compile the flex-generated file, but of course I
cannot compile and link with main, because the scanner-class is
undefined now and inheritance of undefined classes does not work...

Stephan Kuhagen

--
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\

| >>> ...destination anywhere,          -\<,    |
| >>> east or west, I don't care...   (*)/(*)   |
| WWW:   http://www.tzi.de/~stk                 |
\_______________________________________________/

PS: Ich widerspreche der Nutzung oder Uebermittlung meiner
Daten fuer Werbezwecke oder fuer die Markt- und Meinungsforschung

(28 Abs. 3 Bundesdatenschutzgesetz)