最近在写一个XMLDocument库,用的是VS2008EXPR,新建Console项目XMLDoc,为了方便测试,我另外建了一个TestXMLDoc,然后将其加入当前solution.
将TestXMLDoc设为Active project。然后在project dependencies中设置TextXMLDoc对XMLDoc的依赖。
编译:失败.输出大致如下:
2>TestXMLDoc.obj : error LNK2001: unresolved external symbol "public: static class XMLDocument __cdecl XMLDocument::CreateXMLDocumentFromFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?CreateXMLDocumentFromFile@XMLDocument@@SA?AV1@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
2>TestXMLDoc.obj : error LNK2001: unresolved external symbol "public: __thiscall XMLDocument::~XMLDocument(void)" (??1XMLDocument@@QAE@XZ)
2>TestXMLDoc.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall XMLDocument::GetContent(void)" (?GetContent@XMLDocument@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
刚开始怀疑是不是因为XMLDoc.lib没有正确生成,但是因为不会设置project的output项,放弃。然后上网查了一大通,没有解决问题。后来我偶然发现了把project输出设置为lib的方法,把XMLDoc输出为lib,然后再编译,OK!
设置输出为lib的方法如下:
右击XMLDocument,properties->general->Configuration Type设为static lib.
link error 2001的原因肯定是很多的,每个人遇到的情况可能会不同,这篇日记仅适用于类似的情况。