2011-03-06 49 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