ANTLR C 目标和 XMLLib

发布于 2024-11-25 02:43:31 字数 2743 浏览 1 评论 0原文

我有一个用 C 编写的程序,它使用 XMLLib 和从 ANTLR 生成的词法分析器/解析器。

我的包含看起来像:

#include    "MyParser.h"
#include    "MyLexer.h"
#include    "antlr3.h"
#include <libxml/tree.h>
#include <libxml/parser.h>

问题是我的程序拒绝编译,错误如下:

In file included from /usr/include/libxml2/libxml/parser.h:19:0,
                 from /usr/include/libxml2/libxml/globals.h:18,
                 from /usr/include/libxml2/libxml/threads.h:35,
                 from /usr/include/libxml2/libxml/xmlmemory.h:218,
                 from /usr/include/libxml2/libxml/tree.h:1248,
                 from MyProgram.c:4:
/usr/include/libxml2/libxml/valid.h:276:21: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
/usr/include/libxml2/libxml/valid.h:302:21: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
In file included from /usr/include/libxml2/libxml/globals.h:18:0,
                 from /usr/include/libxml2/libxml/threads.h:35,
                 from /usr/include/libxml2/libxml/xmlmemory.h:218,
                 from /usr/include/libxml2/libxml/tree.h:1248,
                 from MyProgram.c:4:
/usr/include/libxml2/libxml/parser.h:800:19: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
In file included from /usr/include/libxml2/libxml/parser.h:808:0,
                 from /usr/include/libxml2/libxml/globals.h:18,
                 from /usr/include/libxml2/libxml/threads.h:35,
                 from /usr/include/libxml2/libxml/xmlmemory.h:218,
                 from /usr/include/libxml2/libxml/tree.h:1248,
                 from MyProgram.c:4:
/usr/include/libxml2/libxml/xmlIO.h:293:19: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
In file included from /usr/include/libxml2/libxml/globals.h:18:0,
                 from /usr/include/libxml2/libxml/threads.h:35,
                 from /usr/include/libxml2/libxml/xmlmemory.h:218,
                 from /usr/include/libxml2/libxml/tree.h:1248,
                 from MyProgram.c:4:
/usr/include/libxml2/libxml/parser.h:961:22: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
/usr/include/libxml2/libxml/parser.h:967:22: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
/usr/include/libxml2/libxml/parser.h:1063:54: error: expected ‘)’ before ‘f’
/usr/include/libxml2/libxml/parser.h:1065:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlGetExternalEntityLoader’
/usr/include/libxml2/libxml/parser.h:1068:19: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant

如果我不包含前两个包含,则所有内容都会正确编译(我用简单的“return 0”替换了我的 main() 函数)。知道是什么原因造成的吗? :(

我的编译命令如下所示:

gcc *.c -c -lantlr3c -I/usr/include/libxml2

编辑:我从 Ubuntu 包管理器安装了 libxml2-dev 包(如果这有影响的话)

I have a program written in C which uses XMLLib and a lexer/parser generated from ANTLR.

My includes look like:

#include    "MyParser.h"
#include    "MyLexer.h"
#include    "antlr3.h"
#include <libxml/tree.h>
#include <libxml/parser.h>

The problem is my program refuses to compile, erroring with:

In file included from /usr/include/libxml2/libxml/parser.h:19:0,
                 from /usr/include/libxml2/libxml/globals.h:18,
                 from /usr/include/libxml2/libxml/threads.h:35,
                 from /usr/include/libxml2/libxml/xmlmemory.h:218,
                 from /usr/include/libxml2/libxml/tree.h:1248,
                 from MyProgram.c:4:
/usr/include/libxml2/libxml/valid.h:276:21: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
/usr/include/libxml2/libxml/valid.h:302:21: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
In file included from /usr/include/libxml2/libxml/globals.h:18:0,
                 from /usr/include/libxml2/libxml/threads.h:35,
                 from /usr/include/libxml2/libxml/xmlmemory.h:218,
                 from /usr/include/libxml2/libxml/tree.h:1248,
                 from MyProgram.c:4:
/usr/include/libxml2/libxml/parser.h:800:19: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
In file included from /usr/include/libxml2/libxml/parser.h:808:0,
                 from /usr/include/libxml2/libxml/globals.h:18,
                 from /usr/include/libxml2/libxml/threads.h:35,
                 from /usr/include/libxml2/libxml/xmlmemory.h:218,
                 from /usr/include/libxml2/libxml/tree.h:1248,
                 from MyProgram.c:4:
/usr/include/libxml2/libxml/xmlIO.h:293:19: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
In file included from /usr/include/libxml2/libxml/globals.h:18:0,
                 from /usr/include/libxml2/libxml/threads.h:35,
                 from /usr/include/libxml2/libxml/xmlmemory.h:218,
                 from /usr/include/libxml2/libxml/tree.h:1248,
                 from MyProgram.c:4:
/usr/include/libxml2/libxml/parser.h:961:22: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
/usr/include/libxml2/libxml/parser.h:967:22: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
/usr/include/libxml2/libxml/parser.h:1063:54: error: expected ‘)’ before ‘f’
/usr/include/libxml2/libxml/parser.h:1065:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xmlGetExternalEntityLoader’
/usr/include/libxml2/libxml/parser.h:1068:19: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant

If I don't include the first two includes everything compiles correctly (I replaced my main() function with a simple 'return 0'). Any idea what could be causing this? :(

My compile command looks like:

gcc *.c -c -lantlr3c -I/usr/include/libxml2

Edit: I installed libxml2-dev package from the Ubuntu package manager if this makes a difference

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧时浪漫 2024-12-02 02:43:31

看起来有些宏观问题。 parser.h 的第 961 行包含 ID,它可能在您的标头之一中定义。

Looks like some macro problems. Line 961 of parser.h includes ID, which may be defined in one of your headers.

榆西 2024-12-02 02:43:31

我不确定是否可以复活这个主题,但是即使我尝试使用“-I /usr/include/libxml2”,对于一个更简单的程序我也遇到了同样的问题。但是,一旦我也传递了链接参数,代码就能够编译。

Libxml.org 当前的常见问题解答 (http://www.xmlsoft.org/FAQ.html )谈论这个:

开发者专区

使用 libxml2 编译或链接程序时出现问题通常是
问题来自于编译器没有得到正确的结果
编译或链接标志。有一个小shell脚本
xml2-config 作为 libxml2 常规安装的一部分安装
提供这些标志的进程。使用

xml2-config --cflags

获取编译标志和

xml2-config --libs

获取链接器标志。通常这是直接从
生成文件为:

CFLAGS=xml2-config --cflags

LIBS=xml2-config --libs

不确定一年前是否已经有了这个有用的提示。

I'm not sure if its ok to resurrect the topic, but I was having the same problem for a more simple program even if I tried to use the "-I /usr/include/libxml2". However, once I passed the linked argument too the code was able to compile.

The current FAQ of Libxml.org (http://www.xmlsoft.org/FAQ.html )talk about this:

Developer corner

Troubles compiling or linking programs using libxml2 Usually the
problem comes from the fact that the compiler doesn't get the right
compilation or linking flags. There is a small shell script
xml2-config which is installed as part of libxml2 usual install
process which provides those flags. Use

xml2-config --cflags

to get the compilation flags and

xml2-config --libs

to get the linker flags. Usually this is done directly from the
Makefile as:

CFLAGS=xml2-config --cflags

LIBS=xml2-config --libs

Not sure if one year ago was already with this useful tip.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文