views:

871

answers:

4

I'm trying to link the LizardTech GeoExpress DSDK into my own application. I use gcc so that we can compile on for platforms. On Linux and Mac this works easily: they provide a static library (libltidsdk.a) and headers and all that we have to do is use them.

Compiling for windows isn't so easy. They've built the library using Microsoft Visual Studio, and we use MinGW. I've read the MinGW FAQ, and I'm running into the problems below. The library is all C++, so my first question: is this even possible?

Just linking against the dll as provided yields "undefined reference" errors for all of the C++ calls (constructors, desctructors, methods, etc).

Based on the MinGW Wiki: http://www.mingw.org/wiki/MSVC%5Fand%5FMinGW%5FDLLs I should be able to use the utility reimp to convert a .lib into something useable. I've tried all of the .lib files provided by LizardTech, and they all give "invalid or corrupt import library". I've tried both version 0.4 and 0.3 of the reimp utility.

Using the second method described in the wiki, I've run pexport and dlltool over the dll to get a .a archive, but that produces the same undefined references.

BTW: I have read the discussion below. It left some ambiguity as to whether this is possible, and given the MinGW Wiki page it seems like this should be doable. If it is impossible, that's all I need to know. If it can be done, I'd like to know how I can get this to happen.

stackoverflow.com/questions/1796209/how-to-link-to-vs2008-generated-libs-from-g

Thanks!

A: 

I'm almost certain that you can't link C++ libraries across compilers like that. I've tried, really hard, but it was a long time ago and I don't remember the details. i think for C libraries is possible, with a lot of hacks.

Chris H
A: 

To use a DLL in Windows, you link against an import library (not the DLL itself). Import libraries typically have the extension .lib (just like static libraries). If you download the Windows SDK, you'll get import libraries for all of the system DLLs.

From your question, it sounds like you might have mixed up the .dll with the .lib. Are you sure reimp doesn't take a DLL as input and make a .LIB import library that's compatible with MinGW?

I just looked up with MinGW is on Wikipedia. According to that article, MinGW comes with redistributable import libraries.

Adrian McCarthy
Based on the MinGW wiki, reimp takes an import library. Running it against the DLL doesn't work either, though I did try it.
IndigoFire
+3  A: 

You can't do this. They have exported C++ classes from their dll, rather than C-functions. The difference is, c++ functions are always exported with names in a mangled form that is specific to a particular version of the compiler.

Their dll is usable by msvc only in that form, and will probably not even work between different versions of msvc, as Microsoft have changed their mangling scheme before.

If you have any leverage, you need to get them to change their evil ways. Otherwise you will need to use MSVC to write a shim dll, that will import all the classes, and re-export them via c functions that return interfaces.

Chris Becke
Thanks, this is exactly the confirmation I was looking for. They do have a c interface, and I'm looking at using that, but it's much less powerful than what's available in C++. I'm also pushing them to release for MinGW.
IndigoFire
I do prefer mingw releases of, well, everything, as it makes deployment really simple when the c-runtime dependency is the universally available msvcrt.dll, rather than the visual studio version specific runtimes msvcr70.dll, msvcr71.dll, msvcr80.dll, msvcr90.dll and now msvcr100.dll.
Chris Becke
A: 

http://www.mingw.org/wiki/DLL may be useful to you.

rogerdpack