Friday, December 14, 2007

Using MingW-Fu to link to MSVC dll's and lib's

Lately my MingW-Fu has improved vastly thanks to the attempts at building Grass, GDAL and Qgis with all the possible dependencies and drivers. Here are some lessons I have learnt :
  • Don't trust libtool - Libtool in MingW is rather hobbled and needs to be fixed for long link lines using a the sed command described here.
  • Use -no-undefined - MingW linker does not like linking to libraries with some undefined symbols, use that linker flag when compiling dependencies.
  • Create shared libraries not static ones for dependencies.
  • Learn you way around the reverse engineering tools for porting from MSVC built static and dynamic libraries, specifically reimp, pexports and dlltool. Sometimes function call definitions need to be renamed using sed or added with @4 or @32 at the end (not sure what purpose this serves), I picked it up while building MySQL libraries for linking.
  • Edit any autoconf or pkgconfig scripts to use MSYS style include and libs location(Those nasty slashes will get you otherwise).
  • Any of these tricks may fail if you have specific name mangling, assembly code and other fancy things in the MSVC libraries. I have still not managed to make a linkable version of libecwj2.dll (ErMapper - Leica ECW/JPEG2000 library), mainly because it contains some of the above features.
Post a Comment