Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Antlr C运行时示例中未定义的引用_C++_C_Antlr - Fatal编程技术网

C++ Antlr C运行时示例中未定义的引用

C++ Antlr C运行时示例中未定义的引用,c++,c,antlr,C++,C,Antlr,我在从Antlr运行C运行时示例时遇到问题 我已经从下载并安装了C运行时。库libantlr3c.a位于/usr/local/lib中,antlr头位于/usr/local/include中。这是antlr图书馆吗?在其他示例中,我看到了提到的“antlr3c”库,而我的前面有“lib” 我下载了示例文件,并将它们放在/home/fraser/examples中名为“example”的文件夹中。然后我让Antlr创建自动生成的解析器和Lexer文件,并从中运行: gcc *.c -o test

我在从Antlr运行C运行时示例时遇到问题

我已经从下载并安装了C运行时。库libantlr3c.a位于/usr/local/lib中,antlr头位于/usr/local/include中。这是antlr图书馆吗?在其他示例中,我看到了提到的“antlr3c”库,而我的前面有“lib”

我下载了示例文件,并将它们放在/home/fraser/examples中名为“example”的文件夹中。然后我让Antlr创建自动生成的解析器和Lexer文件,并从中运行:

gcc *.c -o test -I. -L -llibantlr3c
它给了我以下错误:

/tmp/ccvXlH3T.o: In function `LangDumpDeclNewSSD':
LangDumpDecl.c:(.text+0x89): undefined reference to `antlr3TreeParserNewStream'
/tmp/cc3TwzKz.o: In function `LangLexerNewSSD':
LangLexer.c:(.text+0xd3): undefined reference to `antlr3LexerNewStream'
/tmp/ccpfbaFf.o: In function `LangParserNewSSD':
LangParser.c:(.text+0x8c): undefined reference to `antlr3ParserNewStream'
LangParser.c:(.text+0xf1): undefined reference to `ANTLR3_TREE_ADAPTORNew'
LangParser.c:(.text+0x103): undefined reference to `antlr3VectorFactoryNew'
/tmp/ccpfbaFf.o: In function `decl':
LangParser.c:(.text+0x6ca): undefined reference to `antlr3RewriteRuleSubtreeStreamNewAE'
LangParser.c:(.text+0x76f): undefined reference to `antlr3RewriteRuleTOKENStreamNewAE'
LangParser.c:(.text+0x811): undefined reference to `antlr3RewriteRuleTOKENStreamNewAE'
LangParser.c:(.text+0x85d): undefined reference to     `antlr3RewriteRuleSubtreeStreamNewAEE'
/tmp/ccED3tJV.o: In function `main':
main.c:(.text+0x46): undefined reference to `antlr3AsciiFileStreamNew'
main.c:(.text+0xe0): undefined reference to `antlr3CommonTokenStreamSourceNew'
main.c:(.text+0x1d0): undefined reference to `antlr3CommonTreeNodeStreamNewTree'
collect2: ld returned 1 exit status
我以前使用Antlr的唯一经验是在Java中,我以前使用C/C++的唯一经验是在Visual Studio中,所以我对链接和命令行编译等都是新手。所以我猜这是一个非常简单的错误,涉及错误的链接,或者错误的Antlr库


事先致歉和感谢。

您使用的是没有参数的-L选项。选项-llibantlr3c被视为-L的目录参数,而不是要链接的库。由于链接中没有包含antlr库,因此您将获得所有缺少的符号。另外,-l在库名称前加上'lib',因此请尝试

gcc *.c -o test -I. -lantlr3c

如果libantlr3c.a文件位于非标准目录中,请在3.4版之后添加带有-L标志的目录,请更改为 输入=antlr3FileStreamNew((pANTLR3_UINT8)argv[1],ANTLR3_ENC_8BIT)

不是,例如antlr3AsciiFileStreamNew(argv[1]) 参考中村信二

感谢您的回复和回答,但是现在我得到了:/usr/bin/ld:跳过不兼容的/usr/local/lib/libantlr3c。因此,在搜索-lantlr3c/usr/bin/ld时:跳过不兼容的/usr/local/lib/libantlr3c。在搜索-lantlr3c/usr/bin/ld时:找不到-lantlr3c collect2:ld返回1个退出状态,听起来不太好。另外,很抱歉,我无法在这里获得良好的格式设置。很可能您有32/64位的问题。您有一个32位操作系统和编译器,还有一个64位版本的antlr或其他版本。为您的系统获取正确的版本。啊,是的,在这样做并运行ldconfig之后,它就可以工作了,谢谢!令人尴尬的简单解决方案:)