c++ - LLVM execution engine cannot find my function -
i using llvm's executionengine run module. module contains function called blub returns 5. in c: 
int blub() {   int x = 5;   return x; } here c++ code executing "blub":
// print out of functions, see (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 " << result << std::endl; it should print out names of functions (just "blub") , result, "5".
however, error instead:
blub llvm error: program used external function 'blub' not resolved! so function indeed in module, cannot resolved executionengine. missing step?
from the documentation of getpointertonamedfunction (emphasis mine):
getpointertonamedfunction - method returns address of specified function using dlsym function call.
as such useful resolving library symbols, not code generated symbols.
you should instead call findfunctionnamed , runfunction on result.
Comments
Post a Comment