Hi I'm compiling the following program:
#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;
}
and the g++ compiler reported an error of undefined reference to 'llvm::Module::dump() const'
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.
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 &OS,
AssemblyAnnotationWriter *AAW,
bool ShouldPreserveUseListOrder = false,
bool IsForDebug = false
)
For example:
mod->print(llvm::errs(), nullptr);