Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在llvm(ExecutionEngine创建错误)C++;_C++_Llvm - Fatal编程技术网

C++ 在llvm(ExecutionEngine创建错误)C++;

C++ 在llvm(ExecutionEngine创建错误)C++;,c++,llvm,C++,Llvm,我试图使用从llvm位代码编译和运行函数的公共示例,但它不起作用(我使用的是llvm的最新版本) 这是我的密码 #pragma warning(disable : 4146) #include <iostream> #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/IR/IRBuilder.h" #include &qu

我试图使用从llvm位代码编译和运行函数的公共示例,但它不起作用(我使用的是llvm的最新版本)

这是我的密码

#pragma warning(disable : 4146)

#include <iostream>

#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Verifier.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"

using namespace llvm;

int main(int argc, char* argv[]) {
    InitializeNativeTarget();
    InitializeNativeTargetAsmPrinter();
    InitializeNativeTargetAsmParser();

    llvm::LLVMContext context;
    std::unique_ptr<llvm::Module> m{ new llvm::Module {"test", context} };

    Constant* init_value = ConstantInt::get(Type::getInt32Ty(context), APInt(32, 12));

    GlobalVariable* bsp = new GlobalVariable(*m, Type::getInt32Ty(context), false, GlobalValue::ExternalLinkage, init_value, "bsp", 0/*, GlobalValue::GeneralDynamicTLSModel*/);
    llvm::FunctionType* funcType = llvm::FunctionType::get(Type::getInt32Ty(context), {}, false);
    llvm::Function* mainFunc = llvm::Function::Create(funcType, llvm::Function::ExternalLinkage, "main", m.get());

    llvm::BasicBlock* bb = llvm::BasicBlock::Create(context, "entrypoint", mainFunc);
    IRBuilder<> builder(bb);
    builder.CreateRet(builder.CreateLoad(bsp));

    std::string err;
    llvm::EngineBuilder EB(std::move(m));
    EB.setEngineKind(llvm::EngineKind::JIT).setErrorStr(&err);
    llvm::ExecutionEngine* EE = EB.create();
    if (!EE) {
        std::cerr << "unable to create a jitter: " << err << "\n";
        return 0;
    }
    EE->finalizeObject();

    const auto fa = (int(*)())EE->getFunctionAddress("main");

    printf("%d\n", fa());

    system("pause");
}
我在互联网上查找这个问题的解决方案,据说需要包含文件
MCJIT.h
,但代码显示它包含在内。在函数的末尾,它也会使我崩溃。就像我可以在另一个函数中使用此代码一样,但它会在函数的出口处触发VisualStudio断点

编辑:

我尝试调用LLVMLinkInMCJIT()函数,但没有结果,我在二进制文件中看到了以下内容

00007FF7C0D1AA96 | FF15 FC961A00 |呼叫qword ptr ds:[]

LLVMLinkInInterpreter功能代码

00007FF8BCB6EC30 | C2 0000 | ret 0x0

看起来我需要重建我的llvm-c.dll,我会尝试一下,然后告诉你发生了什么

unable to create a jitter: JIT has not been linked in.