2016-11-08 6 views
1

モジュールを実行するのにLLVMのExecutionEngineを使用しています。このモジュールにはblubという関数があり、それは5を返します。 Cでは:ここLLVM実行エンジンが私の機能を見つけることができません

int blub() { 
    int x = 5; 
    return x; 
} 

「ブラブ」実行するための私のC++のコードは次のとおりです。

// Print out all of the functions, just to see 
for (auto& function : M->functions()) { 
    std::cout << function.getName().str() << std::endl; 
} 

auto engine = EngineBuilder(std::move(M)).create(); 

engine->finalizeObject(); 

using MyFunc = int(); 
auto func = (MyFunc*)engine->getPointerToNamedFunction("blub"); 

auto result = func(); 

std::cout << "result is " << result << std::endl; 

それは5」、すべての関数の名前をプリントアウト(単なる「ブラブ」)およびその結果必要があります"

はしかし、私の代わりにこのエラーが出る:

blub 
LLVM ERROR: Program used external function 'blub' which could not be resolved! 

ので機能はモジュールに確かであるが、それはExecutionEngineによって解決することはできません。私は一歩足りませんか?

答えて

0

the documentation of getPointerToNamedFunction(強調鉱山)から:

getPointerToNamedFunction - この方法は、dlsymを関数呼び出しを使用して指定された関数のアドレスを返します。

このように、コード生成シンボルではなく、ライブラリシンボルの解決にのみ役立ちます。

代わりに結果にfindFunctionNamed、その後runFunctionを呼び出す必要があります。

関連する問題