#error “Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h”

╄→гoц情女王★ 提交于 2019-12-17 16:34:12

问题


I have been trying to follow the tutorial at http://gnuu.org/2009/09/18/writing-your-own-toy-compiler/5/ (using flex, bison and llvm) but when typing the line

g++ -o parser parser.cpp tokens.cpp main.cpp

I get the following errors:

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"

I have seen lots of posts like this on the internet, and most of the answers include defining these constants on the command line or by using gcc Makefile.

I don't understand how to do that, could someone help me out?


回答1:


Append this to your command line:

-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS

For more information about the -D command line option, refer to gcc's documentation on preprocessor options.




回答2:


Based on the docs here, you should be able to fix the problem by adding the following command line options:

-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS

Afterwards, there might be some other errors:

parser.o: In function NInteger::NInteger(long long)': parser.cpp:(.text._ZN8NIntegerC2Ex[_ZN8NIntegerC5Ex]+0x23): undefined reference tovtable for NInteger' parser.o: In function NDouble::NDouble(double)': parser.cpp:(.text._ZN7NDoubleC2Ed[_ZN7NDoubleC5Ed]+0x24): undefined reference tovtable for NDouble'

Try to implement every codeGen in every class without llvm stuff (i.e., change node.h). Then you will be able to compile and run the tutorial.

By the way, when you compile the code, you might want to use llvm-config command the get the option instead of using -D option:

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


来源:https://stackoverflow.com/questions/18965870/error-must-define-stdc-limit-macros-before-including-support-datatypes-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!