gpt4 book ai didi

c++ - 在 C++ 中编译 Lex 输出时出错

转载 作者:行者123 更新时间:2023-11-30 04:34:57 25 4
gpt4 key购买 nike

当我将 Lex 的输出编译为 C++ 时,我得到了这些错误:

$ 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

实际的错误是这些:

$ 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

但我查看了该文件,并没有使用不同签名的 yy_delete_buffer 的多个定义。

我该怎么办?

最佳答案

这两个“候选”函数具有相同的签名,但位于不同的命名空间中。

我所能猜测的是,对于将它放置(或未能放置)在 lang::lexyacc 命名空间中的函数的前向定义,存在某种混淆。

关于c++ - 在 C++ 中编译 Lex 输出时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5668451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com