title: LLVM execution engine cannot find my function
body: <p>I am using LLVM's <code>ExecutionEngine</code> to run a module. The module contains a function called <code>blub</code> that returns <code>5</code>. In C: </p>
  
  <pre><code>int blub() {
    int x = 5;
    return x;
  }
  </code></pre>
  
  <p>Here is my C++ code for executing "blub": </p>
  
  <pre><code>// Print out all of the functions, just to see
  for (auto&amp; function : M-&gt;functions()) {
    std::cout &lt;&lt; function.getName().str() &lt;&lt; std::endl;
  }
  
  auto engine = EngineBuilder(std::move(M)).create();
  
  engine-&gt;finalizeObject();
  
  using MyFunc = int();
  auto func = (MyFunc*)engine-&gt;getPointerToNamedFunction("blub");
  
  auto result = func();
  
  std::cout &lt;&lt; "result is " &lt;&lt; result &lt;&lt; std::endl;
  </code></pre>
  
  <p>It should print out the names of all functions (just "blub") and then the result, "5". </p>
  
  <p>However, I get this error instead: </p>
  
  <pre><code>blub
  LLVM ERROR: Program used external function 'blub' which could not be resolved!
  </code></pre>
  
  <p>So the function is indeed in the module, but it cannot be resolved by the <code>ExecutionEngine</code>. Am I missing a step?</p>