views:

1358

answers:

4

I'm going to be working with a C++ library written in plain C++ (not .NET and without MFC). The library is available compiled using both Visual Studio 2005 / Intel Fortran 9.1 and VS 2008 / Intel Fortran 10.1.

Obviously I'm going to grab the binaries for VS 2008 since that's the environment on my computer but I'm curious if there are reasons why a straight C++ library wouldn't be compatible between VS 2005 and 2008. I'd assume that the name-mangling would be the same but maybe there are other reasons. I haven't used C++ in a long time so I'm a little rusty when it comes to these things.

+2  A: 

The biggest issue you will run into is the usage of the CRT. If the CRT (C RunTime) is statically linked into the DLL, you shouldn't have any issues.

However if the CRT is dynamically linked into the project you may run into trouble. Visual Studio 2005 and 2008 use different versions of the CRT and they cannot easily be loaded togeter. But if one or both of the DLL's statically links the CRT you should be in decent shape.

JaredPar
Thanks. I found this article which details some of the issues with linking http://msdn.microsoft.com/en-us/library/ms235460.aspx. The library I have is basically a file I/O library so dynamic linking is probably a better idea (depending on how it's used).
Dana Robinson
And I just looked at it with dumpbin /imports and the library is dynamically linked to the CRT.
Dana Robinson
+2  A: 

It should probably work. The DLL compiled with VS 2005 will be dependent on VS 2005's implementation of the C standard library (msvcr80.dll), whereas your code will depend on VS 2008's C library (msvcr90.dll). This means that at runtime, both versions of the C libraries will be loaded, which is ok, but it increases your memory usage and slows down your load time by a very small amount.

Adam Rosenfield
+3  A: 

As the other posters have commented, you should be able to work in this way.

However, there is one issue that can be a big one - memory management. The C++ runtimes, in particular, can be tricky.

The biggest issue is that there are some incompatibilities between how the 2005 and 2008 runtimes manage memory. Everything works fine, provided you always allocate your memory in your VS2008 DLL, and always delete the memory allocated from within there within your DLL. This usually requires making some "extra" factory and cleanup methods in your DLL, and exposing these.

If you allocate memory from within your VS 2008 DLL, then delete it from code compiled using VS 2005, or vice versa, you may run into some very difficult to debug problems. It will often work, but have random crashes or instabilities.

Reed Copsey
A: 

hey,

would a dll generated using visual studio 2005, will work for use in a porject which is in vs 2008?

Prashanth
You should ask this as a separate question. Nobody will see it down here.
Dana Robinson