开发者

Error compiling Lex output in C++

开发者 https://www.devze.com 2023-02-25 09:39 出处:网络
When I compile Lex\'s output as C++, I get these errors: $ make [6%] Building CXX object lib/CMakeFiles/lang.dir/lex_lexer.cpp.o

When I compile Lex's output as C++, I get these errors:

$ make
[  6%] Building CXX object lib/CMakeFiles/lang.dir/lex_lexer.cpp.o
/home/michael/Projects/lang/build/lib/lex_lexer.cpp: In function ‘int lang::lexyacc::yylex()’:                                         
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:789:1: warning: label ‘find_rule’ defined but not used
/home/michael/Projects/lang/build/lib/lex_lexer.cpp: In function ‘void lang::lexyacc::yypop_buffer_state()’:
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1542开发者_运维知识库:37: error: call of overloaded ‘yy_delete_buffer(yy_buffer_state*)’ is ambiguous
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1427:10: note: candidates are: void lang::lexyacc::yy_delete_buffer(yy_buffer_state*)
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:303:6: note:                 void yy_delete_buffer(yy_buffer_state*)
/home/michael/Projects/lang/build/lib/lex_lexer.cpp: In function ‘yy_buffer_state* lang::lexyacc::yy_scan_buffer(char*, yy_size_t)’:
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1629:25: error: call of overloaded ‘yy_switch_to_buffer(yy_buffer_state*&)’ is ambiguous
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1354:10: note: candidates are: void lang::lexyacc::yy_switch_to_buffer(yy_buffer_state*)
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:301:6: note:                 void yy_switch_to_buffer(yy_buffer_state*)
/home/michael/Projects/lang/build/lib/lex_lexer.cpp: In function ‘int lang::lexyacc::yylex_destroy()’:
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1834:39: error: call of overloaded ‘yy_delete_buffer(yy_buffer_state*)’ is ambiguous
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1427:10: note: candidates are: void lang::lexyacc::yy_delete_buffer(yy_buffer_state*)
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:303:6: note:                 void yy_delete_buffer(yy_buffer_state*)
/home/michael/Projects/lang/build/lib/lex_lexer.cpp: At global scope:
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:308:13: warning: ‘void yyensure_buffer_stack()’ declared ‘static’ but never defined
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:309:13: warning: ‘void yy_load_buffer_state()’ declared ‘static’ but never defined
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:310:13: warning: ‘void yy_init_buffer(yy_buffer_state*, FILE*)’ declared ‘static’ but never defined
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:361:22: warning: ‘yy_state_type yy_get_previous_state()’ declared ‘static’ but never defined
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:362:22: warning: ‘yy_state_type yy_try_NUL_trans(yy_state_type)’ declared ‘static’ but never defined
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:363:12: warning: ‘int yy_get_next_buffer()’ declared ‘static’ but never defined
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:364:13: warning: ‘void yy_fatal_error(const char*)’ declared ‘static’ but never defined
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1212:17: warning: ‘void lang::lexyacc::yyunput(int, char*)’ defined but not used
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1867:12: warning: ‘int lang::lexyacc::yy_flex_strlen(const char*)’ defined but not used
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1162:26: warning: ‘yy_state_type lang::lexyacc::yy_get_previous_state()’ defined but not used
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1193:26: warning: ‘yy_state_type lang::lexyacc::yy_try_NUL_trans(yy_state_type)’ defined but not used
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1450:17: warning: ‘void lang::lexyacc::yy_init_buffer(yy_buffer_state*, FILE*)’ defined but not used
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1556:13: warning: ‘void lang::lexyacc::yyensure_buffer_stack()’ defined but not used
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1689:13: warning: ‘void lang::lexyacc::yy_fatal_error(const char*)’ defined but not used
make[2]: *** [lib/CMakeFiles/lang.dir/lex_lexer.cpp.o] Error 1
make[1]: *** [lib/CMakeFiles/lang.dir/all] Error 2
make: *** [all] Error 2

The actual errors are these:

$ make 2>&1 | grep 'error:'
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1542:37: error: call of overloaded ‘yy_delete_buffer(yy_buffer_state*)’ is ambiguous
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1629:25: error: call of overloaded ‘yy_switch_to_buffer(yy_buffer_state*&)’ is ambiguous
/home/michael/Projects/lang/build/lib/lex_lexer.cpp:1834:39: error: call of overloaded ‘yy_delete_buffer(yy_buffer_state*)’ is ambiguous

But I looked through the file and there aren't multiple definitions of yy_delete_buffer there with different signatures.

What should I do?


The two 'candidate' functions have identical signatures, but are in different namespaces.

All I can guess is that there's somehow some confusion over a forward definition of the function placing (or failing to place) it in the lang::lexyacc namespace.


Hmm it looks like a strange namespace issue, you have two declarations in two different namespaces, e.g.

 lang::lexyacc::yy_delete_buffer(yy_buffer_state*)

and

 yy_delete_buffer(yy_buffer_state*)

They have the same argument lists but they reside in different namespaces, the other one in lang::lexyacc, the other in the default.

If you can't find out a reason for this, you can give the

 %option c++

option to Flex to get a real C++ scanner class.

0

精彩评论

暂无评论...
验证码 换一张
取 消