title: MXE cross compile links to system libltdl.so as well as mxe package version
body: <p>I'm attempting to cross-build an application from Linux for windows using <a href="http://mxe.cc/" rel="nofollow noreferrer">M Cross Environment</a> which is really just a system of makefiles which help use the Mingw-w64 tools. The build system for the application is autotools.</p>
  
  <p>The project links to <a href="https://www.gnu.org/software/libtool/manual/html_node/Using-libltdl.html" rel="nofollow noreferrer">libltdt</a>, but in the final link command for the program, both the system libltdt.so and the cross-compiled mxe version of libltdt</p>
  
  <p>I configured like this:</p>
  
  <p><code>./configure --host=x86_64-w64-mingw32.static CXXFLAGS="-D_P_WAIT=0 -static -static-libgcc -static-libstdc++" CFLAGS="-D_P_WAIT=0" --enable-static --disable-shared</code></p>
  
  <p>I get an error like below</p>
  
  <pre><code>libtool: link: x86_64-w64-mingw32.static-g++ -D_P_WAIT=0 -static-libgcc -static-libstdc++ -pthread -pthread -Wl,--export-all-symbols -o mbdyn.exe mbdyn.o ../mbdyn/base/.libs/libbase.a -L/opt/mxe/usr/x86_64-w64-mingw32.static/lib -L/opt/mxe/usr/mingw/lib aero/.libs/libaero.a struct/.libs/libstruct.a elec/.libs/libelec.a thermo/.libs/libthermo.a hydr/.libs/libhydr.a base/.libs/libbase.a ../libraries/libmbc/.libs/libmbc_static.a -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. -lgfortran -lquadmath /usr/lib/x86_64-linux-gnu/libltdl.so -ldl ../libraries/libmbwrap/.libs/libmbwrap.a ../libraries/libann/.libs/libmbann.a -L/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.4.0 -L/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.4.0/../../../../x86_64-w64-mingw32.static/lib/../lib -L/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.4.0/../../../../x86_64-w64-mingw32.static/lib /home/rcrozier/src/mbdyn/libraries/liby12/.libs/liby12.a /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.4.0/libgfortran.a -lmingw32 -lmoldname -lmingwex -lmsvcrt /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.4.0/libquadmath.a -ladvapi32 -lshell32 -luser32 -lkernel32 /opt/mxe/usr/x86_64-w64-mingw32.static/lib/libltdl.a -pthread -L/usr/lib/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu
  /usr/lib/x86_64-linux-gnu/libltdl.so: error adding symbols: File in wrong format
  collect2: error: ld returned 1 exit status
  make[2]: *** [mbdyn.exe] Error 1
  </code></pre>
  
  <p>In the last command there are several <code>-L</code> entries like <code>-L/usr/lib/x86_64-linux-gnu</code></p>
  
  <p>It also links explicitly to <code>/usr/lib/x86_64-linux-gnu/libltdl.so</code></p>
  
  <p>but I actually want to link only to, <code>/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libltdl.a</code> which is also specified in the command.</p>
  
  <p>If I remove the <code>-L</code> entries which aren't pointing to mxe tools directories and the reference to <code>libltdl.so</code> and run the command manually this completes successfully and the executeable, <code>mbdyn.exe</code>, is produced, and it runs on a windows machine.</p>
  
  <p>Is this an issue with MXE, or have I done something wrong? How can I fix the problem.</p>