本文介绍了无法链接LLVM与包括Flex和Bison在内的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在编写有关使用Flex,Bison和LLVM编写编译器的教程(http://gnuu.org/2009/09/18/writing-your-own-toy-compiler/),并尝试编译最终的二进制文件失败,导致许多以下未定义引用错误:
I've been working through a tutorial on writing compilers with Flex, Bison, and LLVM (http://gnuu.org/2009/09/18/writing-your-own-toy-compiler/), and attempting to compile the final binary fails with many of the following "undefined reference" errors:
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脚本工作正常---有没有人有任何想法如何解决这些错误?
As far as I know, I have all the necessary includes and the llvm-config script is working correctly --- does anybody have any idea how to resolve these errors?
推荐答案
您需要将源文件放在命令行后面的库
You need to put the libraries AFTER the source files on the command line
这篇关于无法链接LLVM与包括Flex和Bison在内的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!