9

I work on the optimization algorithm so the performance really matters. The algorithm is about 8 times faster when compiled in VS 2010 compared to VS 2008. Googling shows that it is not my fault (see e.g. https://stackoverflow.com/a/5560184/890355). The problem is that the final project must be built under VS 2008.

The solution I tend to is to built my algorithm as DLL in VS 2010 and then link it to the main project. Is it possible to use VC++ 2010 run-time libraries with my DLL under VS 2008? If so, what is the least painful way to do it? Any other ideas? Thanks.

3
  • The C++ compiler used by Visual Studio does not support C++0x if that is what you are asking. Of course you could always use a more recent compiler if you want to avoid upgrading to Visual Studio 2010 and/or Visual Studio 2012. One possible solution is to compile the optimization algorithm itself using a different compiler and just reference the output created by said compiler. Aug 27, 2012 at 13:45
  • 2
    Do your libraries pass objects between each other, and expect each other to deallocate them? Library mixing might work, but there are some pretty limiting caveats (and using the C++ containers can lead to bad magic): stackoverflow.com/questions/6531401/… - in short, it's easier if you can keep everything consistent and use just one C++ runtime.
    – wkl
    Aug 27, 2012 at 13:46
  • 3
    This can only come to a good end when you use the #include files from VS2010. Which won't work, VS2008 can't compile them, especially since you are after the move semantics perf improvements. Aug 27, 2012 at 13:46

3 Answers 3

3

The runtimes are not an issue. Nothing stops you from linking your DLL against the VC2010 runtime and then using that DLL in other projects. It doesn't matter if those projects are built using Visual C++ 2008 or any other language.

The tricky part is designing the DLL interface. Simply exporting some C++ classes is risky since it exposes you to incompatibilities between the different compilers. I think your best bet would be to either expose a C-style interface or use COM. I think COM is the best approach, but if you're unfamiliar with the technology, then a C-style interface will work fine. (COM could also be over-kill if the interface is simple.)

1

If you ask for any other way to combine 2008 and 2010 libraries in one executable other than moving 2010 part outside into a DLL, than the answer is probably "there is no other easy way to achieve this".

But if you don't want to "VC++ 2010 run-time libraries ... under VS 2008" (that is building against 2010 libraries in old 2008 IDE), but "use a 2010-compiled DLL in your 2008-compiled program", it is perfectly possible.

The easiest way, as we do it in our projects, is to build (both .exe and DLL) against statically linked standard libraries (MFC, if you use it) and then use LoadLibrary in your .exe to load the DLL. In the DLL you can export (_declspec (dllexport)) a function (preferably inside extern "C" {} guards) and use it in the .exe through GetProcAddress.

Static linkage and explicit loading save you from a lot of inconsistency bugs caused by different runtimes.

If you are worried about DLL loading and function calling costs, you can try to make these calls as rare as possible (maybe by moving not only the algorithm, but also some more high-level logics into the DLL). See this issie too.

And you can build all your code in one IDE (2010) using native multitargeting (however you will still need to build you main app and DLL separately against v9 and v10 libraries respectively).

1

You can if you're careful, and the MS documentation provides some hints. I have answered this question before here:

Wondering if the lower version of visual studio can use the dll built using higher version of visual studio?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.