undefined reference to `llvm::Module::dump() const` 使用g++编译时出现未定义引用错误。

huangapple go评论51阅读模式
英文:

using g++, undefined reference to `llvm::Module::dump() const'

问题

以下是翻译好的部分:

你好,我正在编译以下程序:

#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Support/SourceMgr.h"

#include <cstdlib>
#include <string>

using namespace llvm;

int main(int argc, char **argv)
{
    std::string target = "'./self_tests/src_huawei/alg5.cpp'";
    std::string cml = "clang -emit-llvm -c " + target + " -o 'result.bc' -O3 -fno-vectorize -fno-slp-vectorize -fno-unroll-loops";

    int result = system(cml.c_str());

    LLVMContext CurrContext;
    SMDiagnostic Err;
    std::unique_ptr<Module> mod = parseIRFile(llvm::StringRef("result.bc"), Err, CurrContext);

    mod->dump();

    return 0;
}

而且g++编译器报告了一个错误:undefined reference to 'llvm::Module::dump() const'

命令行如下:

g++ -m64 -g -lLLVM -lLLVMSupport -lLLVMDemangle -lLLVMDemangle ./src/test.cpp -o test.out

我已经包含了所有名称中包含“llvm”的库,但仍然不起作用。

英文:

Hi I'm compiling the following program:

#include &quot;llvm/Analysis/LoopInfo.h&quot;
#include &quot;llvm/IR/Constants.h&quot;
#include &quot;llvm/IR/Instructions.h&quot;
#include &quot;llvm/IR/Module.h&quot;
#include &quot;llvm/IRReader/IRReader.h&quot;
#include &quot;llvm/Support/SourceMgr.h&quot;

#include &lt;cstdlib&gt;
#include &lt;string&gt;

using namespace llvm;


int main(int argc, char **argv)
{
    std::string target = &quot;&#39;./self_tests/src_huawei/alg5.cpp&#39;&quot;;
    std::string cml = &quot;clang -emit-llvm -c &quot; + target + &quot; -o &#39;result.bc&#39; -O3 -fno-vectorize -fno-slp-vectorize -fno-unroll-loops&quot;;

    int result = system(cml.c_str());
    
    LLVMContext CurrContext;
    SMDiagnostic Err;
    std::unique_ptr&lt;Module&gt; mod = parseIRFile(llvm::StringRef(&quot;result.bc&quot;), Err, CurrContext);

    mod-&gt;dump();
    
    return 0;
}

and the g++ compiler reported an error of undefined reference to &#39;llvm::Module::dump() const&#39;

The command line is as follow:

g++ -m64 -g -lLLVM -lLLVMSupport -lLLVMDemangle -lLLVMDemangle ./src/test.cpp -o test.out

I included all the library have "llvm" in there name, but still not work.

答案1

得分: 1

LLVM将dump函数/功能视为可选项,仅用于调试,不应有期望。相反,您可以使用print

void Module::print(raw_ostream &amp;OS,
    AssemblyAnnotationWriter *AAW,
    bool ShouldPreserveUseListOrder = false,
    bool IsForDebug = false 
)	

例如:

mod-&gt;print(llvm::errs(), nullptr); 
英文:

LLVM considers dump functions/functionality as optional, only for debugging and should not be expected. Instead you can use print

void Module::print(raw_ostream &amp;OS,
    AssemblyAnnotationWriter *AAW,
    bool ShouldPreserveUseListOrder = false,
    bool IsForDebug = false 
)	

For example:

mod-&gt;print(llvm::errs(), nullptr); 

huangapple
  • 本文由 发表于 2023年5月26日 17:13:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76339341.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定