#error“#including Support / DataTypes.h之前必须#define __STDC_LIMIT_MACROS”

时间:2013-09-23 18:04:02

标签: gcc compiler-construction llvm bison flex-lexer

我一直在尝试按照http://gnuu.org/2009/09/18/writing-your-own-toy-compiler/5/上的教程(使用flex,bison和llvm),但在输入行时

  

g ++ -o parser 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。

我不明白该怎么做,有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:13)

将此附加到命令行:

-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS

有关-D命令行选项的详细信息,请参阅gcc's documentation on preprocessor options

答案 1 :(得分:8)

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

-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS

之后,可能还会出现其他一些错误:

  

parser.o:在函数NInteger::NInteger(long long)': parser.cpp:(.text._ZN8NIntegerC2Ex[_ZN8NIntegerC5Ex]+0x23): undefined reference to vtable for NInteger'   parser.o:在函数NDouble::NDouble(double)': parser.cpp:(.text._ZN7NDoubleC2Ed[_ZN7NDoubleC5Ed]+0x24): undefined reference to vtable for NDouble'

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

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

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