在我的代码中包含以下语句
main_module->dump();//main_module 的类型为 llvm::Module*
导致以下链接器错误:
对“llvm::Module::dump() const”的 undefined reference
转储方法驻留在/usr/lib/llvm-5.0/include/llvm/IR/Module.h
我检查了堆栈溢出 ( Using llvm::Function::dump(), linker gives "undefined reference to `llvm::Value::dump() const'" ),当链接器没有以正确的顺序提供库时,我们似乎会收到此错误。但是,我的编译命令中显然有最后的库:
clang++-5.0 -g -O3 main.cpp -o main llvm-config-5.0 --cxxflags --ldflags --system-libs --libs core mcjit native
感谢任何帮助。
奇怪的是,链接器弄清楚了转储方法的类型。它显然包含在包含文件中。那么为什么它会称它为 undefined reference 呢?
我尝试运行的代码: `
# include "llvm/IR/LLVMContext.h"
# include "llvm/IR/Module.h"
# include "llvm/IR/IRBuilder.h"
# include <iostream>
using namespace llvm;
static LLVMContext ctxt;
static IRBuilder<> builder(ctxt);
int main(int argc, char** argv) {
Module* main_module = new Module("main_module", ctxt);
std::cout << main_module->getModuleIdentifier() << "\n";
FunctionType* func_type = FunctionType::get(builder.getInt32Ty(), false);
Function* main_func = Function::Create(func_type,Function::ExternalLinkage, "main", main_module);
if (main_module->getFunction("main")) {
std::cout << "Found function!\n";
}
main_module->dump(); // need this for debugging and testing reasons with LLVM
return 0;
}
最佳答案
除了Subrat的解决方案提供,您可以调整您的代码以避免调用 dump
。您可以通过调用实现相同的目的:
main_module->print(llvm::outs(), nullptr);
同样,如果你想转储一个LLVM函数,你可以这样写:
main_func->print(llvm::outs());
实际上,从 LLVM 5.0.0 开始,dump()
函数就是这样实现的。
关于c++ - LLVM-5.0 Makefile undefined reference 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43723127/