无法将LLVM与包括Flex和Bison在内的项目相关联

时间:2011-03-06 00:14:34

标签: g++ llvm bison flex-lexer

我一直在编写有关使用Flex,Bison和LLVM(http://gnuu.org/2009/09/18/writing-your-own-toy-compiler/)编写编译器的教程,并尝试编译最终的二进制文件失败,出现以下许多“未定义的引用”错误:

g++ -o parser `llvm-config --libs core jit native --cxxflags --ldflags` *.cpp
/tmp/ccl0CSyi.o: In function `NBinaryOperator::codeGen(CodeGenContext&)':
codegen.cpp:(.text+0x2ce): undefined reference to     `llvm::BinaryOperator::Create(llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*,     llvm::Twine const&, llvm::BasicBlock*)'
/tmp/ccl0CSyi.o: In function `NDouble::codeGen(CodeGenContext&)':
codegen.cpp:(.text+0x3db): undefined reference to `llvm::getGlobalContext()'
codegen.cpp:(.text+0x3e3): undefined reference to     `llvm::Type::getDoubleTy(llvm::LLVMContext&)'
/tmp/ccl0CSyi.o: In function `NInteger::codeGen(CodeGenContext&)':
...
collect2: ld returned 1 exit status
make: *** [parser] Error 1

据我所知,我有所有必要的包含,并且llvm-config脚本工作正常---有没有人知道如何解决这些错误?

2 个答案:

答案 0 :(得分:13)

您需要将源文件之后的库放在命令行上

答案 1 :(得分:0)

您可以使用:

clang++ -g -O3 toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core` -o toy

希望这有帮助。