title: How to portably load dynamic libraries and run their initialization code?
body: <p>Using GCC and being on Linux, or probably wherever <code>glibc</code> is available, I can use the <code>dl_open()</code> library function to dynamically load a shared-object/DLL:</p>
  <pre><code>void *dlopen(const char *filename, int flags);
  </code></pre>
  <p>... and this also runs all functions which, in the ELF format, are marked with <code>.init</code>; or in the C/C++ code, are marked with <code>__attribute__((constructor))</code> :</p>
  <p><a href="https://stackoverflow.com/questions/2053029/how-exactly-does-attribute-constructor-work#2053078">How exactly does __attribute__((constructor)) work?</a></p>
  <p>My question is: How can I do the same in a more portable way? I'm interested in portability both to other compilers and other platforms.</p>
  <p>Note: I marked this C++ because that's what I'm using, but obviously a C-ish solution in acceptable - as what I've described above is a C-ish solution.</p>