I am trying to parse a LLVM-IR file(.ll) and do a static analysis..
I found this sample code below, and I tried to build it, but I don't know which library to link.
#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;
}
I gave the below command to build, and it gives me some undefined reference error, which that I think is a linking error.
g++ -I~/llvm/build/include -I~/llvm/llvm/include -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -std=c++11 test.cpp
Which library file should I have to link with -L option in order to build this sample code? I want this to work as a standalone binary, not as a pass within the whole compile procedure.