问题描述
在我的代码中包含以下语句
Including the following statement in my code
main_module->dump(); // main_module is of type llvm::Module*
导致以下链接器错误:
main_module->dump(); // main_module is of type llvm::Module*
causes the following linker error:
undefined reference to 'llvm::Module::dump() const'
转储方法位于/usr/lib/llvm-5.0/include/llvm/IR/Module.h
我检查了堆栈溢出(使用llvm :: Function :: dump (),链接器会给出对`llvm :: Value :: dump()const'的未定义引用".),当链接器未按正确顺序提供库时,似乎会出现此错误.但是,显然我的编译命令中最后有库:
I checked stack overflow (Using llvm::Function::dump(), linker gives "undefined reference to `llvm::Value::dump() const'"), and it seems we get this error when the linker isn't fed the libraries in correct order. However, I clearly have the libraries in the end in my compilation command:
clang++-5.0 -g -O3 main.cpp -o main llvm-config-5.0 --cxxflags --ldflags --system-libs --libs core mcjit native
感谢您的帮助.
奇怪的是,链接器发现了转储方法的类型.显然,它包含在include文件中.那么为什么将其称为未定义引用呢?
The weird thing is, the linker figured out that the type of the dump method. It clearly went in the include file. So why would it call it an undefined reference?
我正在尝试运行的代码:`
Code I am trying to run:`
# 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;
}
推荐答案
好像ASMWriter.cpp
的定义在ASMWriter.cpp
中,似乎已被弃用.同样,ASMWrite.cpp
的调试方法引用debug.cpp
Seems like the definition for dump
is in ASMWriter.cpp
, which seems to be depracated.Also, ASMWrite.cpp
's debug method refers to dbgs()
which is in debug.cpp
我通过复制debug.cpp
和Module::dump()
(来自ASMWriter.cpp,因为我不需要整个代码,因此只需要该文件中的特定子例程)例程并将其放入我的cpp中来解决了该问题.文件.
I fixed the problem by copying over debug.cpp
and the Module::dump()
(from ASMWriter.cpp--since I don't need the whole code, only a specific subroutine from this file) routine and putting it in my cpp file.
这篇关于LLVM-5.0 Makefile未定义引用失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!