我有用c ++编写的自定义函数,并且它们使用了许多c ++标准库,例如iostream
,map
,vector
,我可以使用{ {1}},但找不到addObjectFile
,我如何将它们与JIT链接起来?
我的案子:
ffi.cpp
standard libraries' functions
main.cpp ,#include <iostream>
extern "C" int add(int a, int b) {
std::cout << ">>add function run" << std::endl;
return a + b;
}
由built/ffi
clang++ ffi.cpp -c -o build/ffi
可以找到int main(int argc, char *argv[]) {
InitLLVM X(argc, argv);
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
ThreadSafeContext context(std::make_unique<LLVMContext>());
ExitOnError ExitOnErr;
auto JTMB = ExitOnErr(JITTargetMachineBuilder::detectHost());
JTMB.setCodeModel(CodeModel::Small);
auto jit =
ExitOnErr(LLJITBuilder()
.setJITTargetMachineBuilder(std::move(JTMB))
.create());
char ffi_file[] = "build/ffi";
jit->addObjectFile(ExitOnErr(errorOrToExpected(MemoryBuffer::getFileAsStream(ffi_file))));
函数,但是无法找到iostream的函数,并且运行时出错:
add