views:

144

answers:

4

I have a c++ and a c# project in Visual Studio 2008. The c++ project uses an API that was built in VS2005. I need that c++ project to reference the standard library files from VS2005. The order that the compiler searches the include directories keeps pointing to the include files from VS2008, specifically the vector file. It crashes the program when running in Release when it references the vector file from VS2008. How do I force the c++ project to use the include directories from VS2005?

A: 

This is a total hack, but you might be able to explicitly include a specific implementation of vector by replacing:

#include <vector>

...with:

#include "C:\Program Files (x86)\Microsoft Visual Studio 8.0\VC\include"

But if you need your VS2008 project to use an older version of the STL, then I smell something pretty bad. Perhaps your DLLs don't seperate the interface from the implementation?

John Dibling
I need to force the directory in the properties somewhere. The #include <vector> is in the API code not my own so I can't mess with that.
Laurie
If the API code you are mentioning has STL stuff in the public classes, then the API you are using is broken. The easiest thing to do in this case is just use VS2005.
John Dibling
A: 

If you want to use the VS2005 headers you really should build with VS2005. You might get things to work by fiddling around with the include file path, but I'd expect a lot of headaches. I'm sure it's not supported, and if the headers want to pull in anything from the CRT library (ie., what you're using happens to not be header-only stuff) it'll likely not work very well if at all.

Michael Burr
A: 

Here are two alternatives you can try.

First, rename the VS2005 version of <vector> to <vector_vs8>. Add an include path to this directory, and change

#include <vector>

...to

#include "vector_vs8"

Second, change some project settings around to use ONLY VS8 includes rather than VS9 includes:

Project>Settings>Configuration Properties>C/C++>General>Additional Include Directories set to point to the include directories for VS2005. This will include ALL vs2005 files, not just <vector>

*Project>Settings>Configuration Properties>C/C++>Preprocessor>*Ignore Standard Include Path set to TRUE

John Dibling
A: 

If the program crashes in a release build, the problem is probably with your code rather than the library code, and reverting back to VS2005 is just sticking your head in the sand. Moreover the problem is likely be to do with the compiler code generation rather than the compiler library, so using a hybrid of VS2010 and VS2005 may not resolve the problem, and I would say is likely to introduce far greater problems. Optimisation often breaks code that relies on undefined behaviour, since the compiler may legitimately behave in a different manner. You should fix your code.

Perhaps a better quick-fix that using an old library is to apply selective optimisation: disable the optimisation specifically on the module that is giving you the problem. That will also help isolate the problem, and without optimisation set, that module can be more easily debugged in the debugger.

Also simply referencing a different header file is probably insufficient; you will also need to link the VC2005 library as well; otherwise the library and the header may mismatch. In short, do not use a 'solution' that is more complex and error prone than the original problem!

Clifford