我已经使用CMake和VS 2015下载了源代码并构建了LLVM。
我的示例程序如下:
#include <iostream>
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/CFG.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() << "Usage: " << argv[0] << " <IR file>\n";
return 1;
}
// Parse the input LLVM IR file into a module.
SMDiagnostic Err;
LLVMContext TheContext;
std::unique_ptr<Module> Mod = parseIRFile(argv[1], Err, TheContext);
if (!Mod) {
Err.print(argv[0], errs());
return 1;
}
// ... use module
}
在链接器库路径中包含LLVM lib目录后,我收到以下链接错误:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: __thiscall llvm::LLVMContext::LLVMContext(void)" (??0LLVMContext@llvm@@QAE@XZ) referenced in function _main LLVM_IRReader c:\Users\nlykkei\documents\visual studio 2015\Projects\LLVM_IRReader\LLVM_IRReader\Main.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: __thiscall llvm::Module::~Module(void)" (??1Module@llvm@@QAE@XZ) referenced in function "public: void * __thiscall llvm::Module::`scalar deleting destructor'(unsigned int)" (??_GModule@llvm@@QAEPAXI@Z) LLVM_IRReader c:\Users\nlykkei\documents\visual studio 2015\Projects\LLVM_IRReader\LLVM_IRReader\Main.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "class llvm::raw_ostream & __cdecl llvm::errs(void)" (?errs@llvm@@YAAAVraw_ostream@1@XZ) referenced in function _main LLVM_IRReader c:\Users\nlykkei\documents\visual studio 2015\Projects\LLVM_IRReader\LLVM_IRReader\Main.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: void __thiscall llvm::SMDiagnostic::print(char const *,class llvm::raw_ostream &,bool,bool)const " (?print@SMDiagnostic@llvm@@QBEXPBDAAVraw_ostream@2@_N2@Z) referenced in function _main LLVM_IRReader c:\Users\nlykkei\documents\visual studio 2015\Projects\LLVM_IRReader\LLVM_IRReader\Main.obj 1
有谁知道如何解决这些错误?我在例如LLVM构建目录中看到了raw_ostream.obj ...
答案 0 :(得分:0)
我从未使用LLVM,但根据您的错误消息,链接器未能成功找到LLVM类实现。
就我而言,包括LLVM lib目录是不够的。您还必须包含要链接的LLVM库(实现LLVM类的.lib)。