小编iza*_*azu的帖子

使用 llvm 库构建时如何链接?

我正在尝试解析 LLVM-IR 文件(.ll)并进行静态分析。

我在下面找到了这个示例代码,我尝试构建它,但我不知道要链接哪个库。

#include <iostream>
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

int main(int argc, char** argv)
{
    if (argc < 2) {
        errs() << "Expected an argument - IR file name\n";
        exit(1);
    }

    LLVMContext &Context = getGlobalContext();
    SMDiagnostic Err;
    std::unique_ptr<Module> Mod = parseIRFile(argv[1], Err, Context);

    if (Mod) {
        std::cout << "Mod is not null" << std::endl;
    }
    else {
       std::cout << "Mod is null" << std::endl;
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我给出了下面的命令来构建,它给了我一些未定义的参考错误,我认为这是一个链接错误。

g++ …
Run Code Online (Sandbox Code Playgroud)

compiler-construction static-analysis llvm llvm-clang llvm-ir

2
推荐指数
1
解决办法
1666
查看次数