title: Cause of "entry point could not be located" in unrelated DLL?
body: <p>Before you dismiss this question as a repeat, this question is different than the many other similar questions on SO because the <strong>function</strong> in the error message is <strong>completely unrelated</strong> to the <strong>DLL</strong>.</p>
  
  <h3>The app and version info</h3>
  
  <p>I've got a 32-bit app in Visual Studio 2008 RTM which uses a MATLAB Compiler 4.17 (R2012a) generated DLL, Glib (2.32.4, binaries from GStreamer SDK 2012.9 32-bit), and Qt (4.8.3-vs2008), all running on Windows 7 x64 SP1.</p>
  
  <h3>The problem</h3>
  
  <p>The <strong>debug build runs fine</strong>, but in release I get the infamous <code>The procedure entry point libXXXInitialize could not be located in the dynamic link library libglib-2.0-0.dll.</code> The bizarre thing is that this libXXXInitialize function (which does exist in the MATLAB-based DLL) is <strong>totally unrelated</strong> to libglib-2.0-0.dll.</p>
  
  <h3>My research</h3>
  
  <p>I checked the obvious, ensuring that all libraries were compiled with VS2008 (except for GStreamer/GLib which is compiled with mingw, but since it's straight C there shouldn't be any issues), and checking for any other versions of the DLLs in the path. It seems like it must be some sort of linker problem.</p>
  
  <h3>Update 1</h3>
  
  <p>In Dependency Walker x86, it shows this <code>libXXXInitialize</code> as an unresolved (parent) import from not only libglib-2.0-0.dll, but all the other GLib/GStreamer DLLs as well, however the function is correctly resolved in the DLL where it should be found, libXXX.dll.</p>
  
  <h3>Update 2</h3>
  
  <p>I removed the call to <code>libXXXInitialize</code> and called <code>mclInitializeApplication</code> from the MATLAB Compiler Runtime, and now that function is failing to be resolved from the glib DLL.</p>
  
  <p><strong>However I found a solution</strong> (at least temporary), changing the linker options from <a href="http://msdn.microsoft.com/en-us/library/bxwfs976%28v=vs.90%29.aspx" rel="nofollow"><code>/OPT:REF</code></a> to <code>/OPT:NOREF</code> fixed the problem (so the linker "<em>keeps functions and/or data that are never referenced</em>). The bizarre thing is, I certainly use the <code>mclInitializeApplication</code> function explicitly, and if I turn on <code>/VERBOSE:REF</code>, it doesn't show it being removed.</p>
  
  <h3>Update 3</h3>
  
  <p>Finally found mention of this somewhere else, on the <a href="http://sourceware.org/bugzilla/show_bug.cgi?id=12633" rel="nofollow">bugtracker for binutils</a>. I found this in <a href="http://cgit.freedesktop.org/gstreamer-sdk/cerbero/tree/data/vs/msvc/common.props#n15" rel="nofollow">a MSVC2010 property sheet</a> as part of the GStreamer SDK. Suggested workaround is what I'm already doing, disabling OptimizeReferences.</p>
  
  <p>If anyone can tell me why this is happening, I'll mark it as the answer.</p>