LLVM-5.0 MakeFile未定义的参考失败

LLVM-5.0 Makefile undefined reference fail

本文关键字:参考 失败 未定义 MakeFile LLVM-5      更新时间:2023-10-16

包括我的代码中的以下语句

main_module->dump(); // main_module is of type llvm::Module*

导致以下链接器错误:

undefined reference to 'llvm::Module::dump() const'

转储方法位于/usr/lib/llvm-5.0/include/llvm/IR/Module.h

我检查了堆栈溢出(使用llvm :: function :: dump((,Linker给出了"未定义的引用" llvm :: value :: value :: dump((const'&quort'&quort;(,当我们似乎在链接器未按正确的顺序馈送库。但是,我显然在汇编命令中最终有库:

clang++-5.0 -g -O3 main.cpp -o main llvm-config-5.0 --cxxflags --ldflags --system-libs --libs core mcjit native

任何帮助都将不胜感激。

很奇怪的是,链接器确定了转储方法的类型。它显然进入了包含文件。那么,为什么它将其称为未定义的参考?

代码我正在尝试运行:

# 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()函数的方式。

似乎dump的定义在ASMWriter.cpp中,似乎被剥夺了。另外,ASMWrite.cpp的调试方法是指debug.cpp中的CC_11

我通过复制debug.cppModule::dump()(来自asmwriter.cpp-- since我不需要整个代码,只有此文件中的特定子例程(来解决问题。