VS10“附加包含目录”指向VS9包含

时间:2010-08-19 22:20:10

标签: visual-studio-2010

我与VS9并排安装了VS10并使用它创建了一个非常简单的应用程序:

#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;
}

这会产生许多非常奇怪的编译器错误:

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)

...这让我头疼了一段时间,直到我发现错误的标题是#include - ed。而不是VS10版本的<vector>等,VS9文件是#include - ed。反过来,我假设这是因为$(IncludePath)变量定义为: alt text

当我去工具&gt;选项&gt;项目和解决方案&gt; VC ++目录来更改此项目和所有未来项目的全局设置时,我发现了一个不愉快的事实:

alt text

那么如何更改此全局设置?安装程序清楚地设置错误。

1 个答案:

答案 0 :(得分:6)

以下是通过UI更改设置文件的步骤:

  • 单击View.Property Manager打开属性管理器。

  • 展开项目节点,然后展开Configuration | Platform节点,您将看到每个Configuration | Platform的“Microsoft.cpp..users”文件。这些是全局设置的文件,类似于旧工具/选项/ VC ++目录。

  • 多选“Microsoft.cpp..users”,右键单击并打开属性页面窗口

  • 在属性页面窗口中,单击左窗格中的“VC ++目录”(例如),为“包含目录”等目录添加新路径。用分号分隔

  • 确保在关闭Visual Studio之前保存设置。

  • 重新启动Visual Studio,新设置将生效。

如果您只想更改特定项目的设置,可以右键单击项目并调出属性页面。更改“VC ++目录”的设置,这些设置将保留到项目文件中。

相关问题