I installed VS10 side-by-side with VS9 and created a very simple application using it:
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
class A
{
};
class B : public A
{
};
A* get_a() { return new B; }
int main()
{
vector<A*> a_list;
vector<B*> b_list;
generate_n(back_inserter(a_list), 10, get_a);
return 0;
}
This generated a number of very odd compiler errors:
1>hacks_vs10.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::_Container_base_secure::_Orphan_all(void)const " (__imp_?_Orphan_all@_Container_base_secure@std@@QBEXXZ) referenced in function "protected: void __thiscall std::vector<class A *,class std::allocator<class A *> >::_Tidy(void)" (?_Tidy@?$vector@PAVA@@V?$allocator@PAVA@@@std@@@std@@IAEXXZ)
1>hacks_vs10.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (__imp_??1_Container_base_secure@std@@QAE@XZ) referenced in function "protected: __thiscall std::_Container_base_aux_alloc_empty<class std::allocator<class A *> >::~_Container_base_aux_alloc_empty<class std::allocator<class A *> >(void)" (??1?$_Container_base_aux_alloc_empty@V?$allocator@PAVA@@@std@@@std@@IAE@XZ)
1>hacks_vs10.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (__imp_??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) referenced in function "protected: static void __cdecl std::vector<class A *,class std::allocator<class A *> >::_Xlen(void)" (?_Xlen@?$vector@PAVA@@V?$allocator@PAVA@@@std@@@std@@KAXXZ)
1>hacks_vs10.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) referenced in function "protected: staticvoid __cdecl std::vector<class A *,class std::allocator<class A *> >::_Xlen(void)" (?_Xlen@?$vector@PAVA@@V?$allocator@PAVA@@@std@@@std@@KAXXZ)
1>hacks_vs10.obj : error LNK2019:开发者_如何学编程 unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) referenced in function "public: __thiscall std::logic_error::logic_error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0logic_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z)
1>hacks_vs10.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (__imp_?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) referenced in function "public: virtual char const * __thiscall std::logic_error::what(void)const " (?what@logic_error@std@@UBEPBDXZ)
1>hacks_vs10.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base_secure::_Container_base_secure(void)" (__imp_??0_Container_base_secure@std@@QAE@XZ) referenced in function "protected: __thiscall std::_Container_base_aux_alloc_empty<class std::allocator<class A *> >::_Container_base_aux_alloc_empty<class std::allocator<class A *> >(class std::allocator<class A *>)" (??0?$_Container_base_aux_alloc_empty@V?$allocator@PAVA@@@std@@@std@@IAE@V?$allocator@PAVA@@@1@@Z)
...which made me scratch my head for some time, until I discovered that the wrong headers were being #include
-ed. Instead of the VS10 version of <vector>
etc, the VS9 files are #include
-ed. This, in turn, I assume is because the $(IncludePath)
variable is defined as:
When I went to Tools>Options>Projects and Solutions>VC++ Directories to change the global setting for this and all future projects, I discovered an unhappy truth:
So how do I change this global setting? The installer clearly set it incorrectly.
Here are the steps to change the settings file through UI:
Open up property manager by clicking on View.Property Manager.
Expand the project node and then the Configuration|Platform nodes, you will see "Microsoft.cpp..users" file for each Configuration|Platform. These are the files for the global settings, similar to the old tools/Options/VC++ Directories.
Multi-Select "Microsoft.cpp..users", right click and bring up the property page window
In the property page window, click on "VC++ Directories" (for example) in the left pane, add new paths for the directories such as "Include Directories". separated by semicolons
Make sure to save the settings before shutting down Visual Studio.
Re-launch Visual Studio and the new settings will be in effect.
If you would like to only change the settings for a specific project, you can right click on the project and bring up the property page. Change the settings for “VC++ Directories”, these settings will be persisted to the project file.
精彩评论