Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%option c++ is not compatible with %option noyywrap - linker error: multiple definition #472

Open
ghost opened this issue Dec 23, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Dec 23, 2020

There seems to be a bug in flex (master) for C++ scanner generation at in src/main.c at line 1679:

 		if (!do_yywrap) {
			outn("\nint yyFlexLexer::yywrap() { return 1; }");
		}

The definition of yyFlexLexer::yywrap() appears in both the header and implementation file. Prefixing with inline solves the problem, but maybe a better solution would be to only output to the implementation file?

@ghost
Copy link
Author

ghost commented Dec 24, 2020

@lexxmark maybe you would be interested in applying the same fix to win_flex?

@ghost
Copy link
Author

ghost commented Jan 8, 2021

Just to clarify the issue is with the header generated by flex, as shown in this example program:

lexer_bug.l:

%option c++ noyywrap outfile="ScannerX.cpp" header="ScannerX.hpp"

%%

.	return 0;

main.cpp:

#include "ScannerX.hpp"

int main() {
    FlexLexer *lex = new yyFlexLexer;
    lex->yylex();
}
$ flex lexer_bug.l
$ g++ ScannerX.cpp main.cpp
/usr/bin/ld: /tmp/cc2Aqsft.o: in function `yyFlexLexer::yywrap()':
main.cpp:(.text+0x0): multiple definition of `yyFlexLexer::yywrap()'; /tmp/ccmi47fP.o:ScannerX.cpp:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status

Two solutions are to #include <FlexLexer.h> instead or the fix to src/main.c above. I still believe the code is broken however, as it generates a header which cannot safely be referenced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants