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?
Based on the docs here, you should be able to fix the problem by adding the following command line options:
Afterwards, there might be some other errors:
Try to implement every codeGen in every class without
llvm
stuff (i.e., changenode.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:Append this to your command line:
For more information about the
-D
command line option, refer to gcc's documentation on preprocessor options.