title: C++ Dynamically load arbitrary function from DLL into std::function
body: <p>How can I load an arbitrary <em>dynamic-link library</em> (dll) function into a <code>std::function</code> object using a single function?</p>
  
  <p>For example I would like to compile two functions into a dll:</p>
  
  <pre><code>// test.dll
  
  int plusFive(int value) {
      return value + 5;
  }
  
  void printHello() {
      std::cout &lt;&lt; "Hello!" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>And load them both at runtime using a single function like this:</p>
  
  <pre><code>// main.cc
  
  #include &lt;functional&gt;
  
  int main() {
      std::function&lt;int(int)&gt; func1(loadDllFunc("test.dll", "plusFive"));
      std::function&lt;void()&gt; func2(loadDllFunc("test.dll", "printHello"));
  }
  </code></pre>