Gcc #“错误”;必须在“包括支持/数据类型.h”之前定义“U STDC”U LIMIT“U宏”;

Gcc #“错误”;必须在“包括支持/数据类型.h”之前定义“U STDC”U LIMIT“U宏”;,gcc,compiler-construction,llvm,bison,flex-lexer,Gcc,Compiler Construction,Llvm,Bison,Flex Lexer,我一直试图在(使用flex、bison和llvm)上遵循教程,但在键入行时 g++-o解析器parser.cpp tokens.cpp main.cpp 我得到以下错误: In file included from /usr/local/include/llvm/Support/PointerLikeTypeTraits.h:18:0, from /usr/local/include/llvm/ADT/PointerIntPair.h:17,

我一直试图在(使用flex、bison和llvm)上遵循教程,但在键入行时

g++-o解析器parser.cpp tokens.cpp main.cpp

我得到以下错误:

In file included from /usr/local/include/llvm/Support/PointerLikeTypeTraits.h:18:0,
                 from /usr/local/include/llvm/ADT/PointerIntPair.h:17,
                 from /usr/local/include/llvm/IR/Use.h:28,
                 from /usr/local/include/llvm/IR/Value.h:17,
                 from node.h:3,
                 from parser.y:2:
/usr/local/include/llvm/Support/DataTypes.h:48:3: erreur: #error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
/usr/local/include/llvm/Support/DataTypes.h:52:3: erreur: #error "Must #define __STDC_CONSTANT_MACROS before " "#including Support/DataTypes.h"
parser.y: In function ‘void yyerror(const char*)’:
parser.y:6:58: erreur: ‘printf’ was not declared in this scope
In file included from /usr/local/include/llvm/Support/PointerLikeTypeTraits.h:18:0,
                 from /usr/local/include/llvm/ADT/PointerIntPair.h:17,
                 from /usr/local/include/llvm/IR/Use.h:28,
                 from /usr/local/include/llvm/IR/Value.h:17,
                 from node.h:3,
                 from tokens.l:3:
/usr/local/include/llvm/Support/DataTypes.h:48:3: erreur: #error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
/usr/local/include/llvm/Support/DataTypes.h:52:3: erreur: #error "Must #define __STDC_CONSTANT_MACROS before " "#including Support/DataTypes.h"
In file included from /usr/local/include/llvm/Support/PointerLikeTypeTraits.h:18:0,
                 from /usr/local/include/llvm/ADT/PointerIntPair.h:17,
                 from /usr/local/include/llvm/IR/Use.h:28,
                 from /usr/local/include/llvm/IR/Value.h:17,
                 from node.h:3,
                 from main.cpp:2:
/usr/local/include/llvm/Support/DataTypes.h:48:3: erreur: #error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
/usr/local/include/llvm/Support/DataTypes.h:52:3: erreur: #error "Must #define __STDC_CONSTANT_MACROS before " "#including Support/DataTypes.h"
我在互联网上看到过很多类似的帖子,大多数答案包括在命令行或使用gcc Makefile定义这些常量


我不知道怎么做,有人能帮我吗?

将此附加到命令行:

-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
有关
-D
命令行选项的更多信息,请参阅。

根据文档,您应该能够通过添加以下命令行选项来解决此问题:

-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
之后,可能会出现一些其他错误:

parser.o:在函数
NInteger::NInteger(long)”中:
parser.cpp:(.text._ZN8NIntegerC2Ex[_ZN8NIntegerC5Ex]+0x23):未定义对
vtable for NInteger's的引用 parser.o:在函数
NDouble::NDouble(double)”中:
parser.cpp:(.text.\u ZN7NDoubleC2Ed[\u ZN7NDoubleC5Ed]+0x24):未定义对
vtable for NDouble'的引用

尝试在没有
llvm
内容的每个类中实现每个codeGen(即,更改
node.h
)。然后您将能够编译并运行教程

顺便说一下,编译代码时,您可能希望使用
llvm config
命令获取选项,而不是使用
-D
选项:

g++ -c `llvm-config --cppflags`  xxxx.cpp

@很遗憾,在添加此命令行选项后,我仍然会遇到错误。有什么线索吗?我在OSX上。@gideon对不起,不。你最好问一下。