2011-03-06 52 views
5

我一直在通过使用Flex,野牛和LLVM编译器写的教程工作(http://gnuu.org/2009/09/18/writing-your-自己的玩具编译/),并试图编译最终的二进制失败,很多下面的“未定义的引用”错误:无法连结针对LLVM与项目包括Flex和Bison

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-配置脚本工作正常---有没有人有任何想法如何解决这些错误?

回答

13

您需要把库的源文件后,在命令行

+1

谢谢!你是最棒的。 – Dylon 2011-03-06 03:30:22

0

。您可以使用:

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

希望这有助于。

+0

你怎么知道这个作品?你能用原版教程例子来试试吗? – mjuarez 2015-04-11 20:19:17