我正在編寫一個LLVM腳本引擎,JIT使用自定義語言編譯腳本代碼。我的問題是我無法調用外部函數(即使C99 erf()函數失敗)。將LLVM JIT代碼鏈接到外部C++函數
例如,如果我爲extern「C」的ERF功能,
extern "C" double erft(double x){
return erf(x);
}
,並創建具有外部鏈接的功能
std::vector<const Type*> Double1(1,Type::getDoubleTy(getGlobalContext()));
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),Double1,false);
Function *erft = Function::Create(FT,Function::ExternalLinkage,"erft",TheModule);
運行我的埃爾夫特河腳本(0.0時收到以下錯誤消息):
LLVM ERROR: Program used external function 'erft' which could not be resolved!
手動進行映射,
void ExecutionEngine::addGlobalMapping(const GlobalValue * erfF, void * erft);
會得到我下面的錯誤:
declaration of `void llvm::ExecutionEngine::addGlobalMapping(const llvm::GlobalValue*, void*)' outside of class is not definition
很顯然,我做的事情非常錯誤的。任何幫助,將不勝感激
未來訪問者的警告:答案是引用不推薦的方法。 – antipattern 2017-08-31 08:43:16
[this]的答案(https://stackoverflow.com/questions/48105342/llvm-jit-add-library-to-module)問題顯示瞭如何使用非棄用方法來做到這一點。 – 2018-01-05 15:12:56