我有一个用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软件包,如果这有所不同
答案 0 :(得分:1)
看起来像是一些宏观问题。 parser.h的第961行包含ID,可以在其中一个标题中定义。
答案 1 :(得分:0)
我不确定是否可以恢复该主题,但即使我尝试使用“-I / usr / include / libxml2”,我也遇到了一个更简单程序的问题。但是,一旦我传递了链接参数,代码就能够编译。
Libxml.org(http://www.xmlsoft.org/FAQ.html)的当前常见问题解答说明了这一点:
开发者角落
使用libxml2编译或链接程序的麻烦通常是 问题来自编译器没有得到正确的事实 编译或链接标志。有一个小的shell脚本 xml2-config作为libxml2常规安装的一部分安装 提供这些标志的过程。使用
xml2-config --cflags
获取编译标志和
xml2-config --libs
获取链接器标志。通常这是直接从 Makefile为:
CFLAGS =
xml2-config --cflags
LIBS =
xml2-config --libs
不确定一年前是否有这个有用的提示。