英文:
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 "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.
答案1
得分: 1
LLVM将dump
函数/功能视为可选项,仅用于调试,不应有期望。相反,您可以使用print
。
void Module::print(raw_ostream &OS,
AssemblyAnnotationWriter *AAW,
bool ShouldPreserveUseListOrder = false,
bool IsForDebug = false
)
例如:
mod->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 &OS,
AssemblyAnnotationWriter *AAW,
bool ShouldPreserveUseListOrder = false,
bool IsForDebug = false
)
For example:
mod->print(llvm::errs(), nullptr);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论