VS2010 exe statically linking to a lib built in VS2008

Hey all.

I'm trying to find a way to statically link to a library. The problem is, the program I'm working on is being built with VS2010, whereas the lib was built with VS2008.

Initial attempts result in linker errors, presumably due to the mismatching runtime lib versions.

Unfortunately, the obvious solution of "build both of them in the same version of VS" is not an option for me, due to some restraints of each project that are out of my control.

So does anyone know if this can even be done? I've been googling to try and find a solution but I haven't been successful yet.

If static linking won't work, would dynamic linking? I'd prefer static if possible, but if it's not possible I might be able to switch this to dynamic.

If anyone has any input/articles that they can link to, I'd appreciate it. Any help at this point would be useful.

Thanks.


EDIT: I was able to get dynamic linking working, but I'd still prefer static linking if at all possible. Any input appreciated.
Last edited on
If the DLL uses C++ linkage, then I'm pretty sure that it's not going to be possible to use the library directly. Name manging and memory handling issues will prevent you from using the lib/DLL with a different compiler, or even a different version of the CRT for that matter.

If you have access to a VS2008, you could build a DLL which adds a C interface and then use that with your VS2010 code.
Last edited on
That's what I was thinking as well. But it turns out VS2008 and VS2010 are similar enough so that name mangling doesn't become an issue. The only issue with static linking is that they're both trying to link to different versions of the runtime.

Dynamic linking is working as long as I'm careful not to pass any instantiations of runtime objects (strings, FILE*s, etc) across the DLL boundary. Also I heard that you can't pass ownership either (ie: new something in the DLL and delete it in the EXE would be a problem).

The API I'm dealing with does pass strings across the lib boundary, so I made a little wrapper class that basically extracts the char array from a string and passes that across the DLL boundary, where it's assigned to a new string. Then on destruction it does the reverse to get the string back to the EXE.

But yeah.. it's working. I just wish I could link the lib in statically. But it doesn't look like that's going to be an option. If it is, though, I'd still love to hear ideas.

Thanks!
It sounds like you're doing the right thing, given the API uses strings.

If the two DLLs are linking to different versions of the CRT, then memory will be allocated from different heaps in the two DLLs. Hence the prob. passing strings -- and anything else which uses heap memory -- back and forth.
Topic archived. No new replies allowed.