现在的位置: 首页 > 综合 > 正文

Poco STLPort boost 调试版本链接出错

2018年02月08日 ⁄ 综合 ⁄ 共 2882字 ⁄ 字号 评论关闭

如果一个工程中有这三个东西 Poco  STLPort  boost 那么它们就会打架

刚开始一编译出错了由于boost存在的原因它会出这么个错误信息:

boost\config\auto_link.hpp(204): fatal error C1189: #error : "Build options aren't compatible with pre-built libraries"

解决办法:

按照 STLPort 官网上的说法我们在 项目属性->c/c++->命令行 添加 /D_STLP_DEBUG

参考: http://www.stlport.org/doc/debug_mode.html

 

这回boost不报错了,Poco又开始报错了

我的用到的是poco中的xml, 链接出错

错误信息:

错误        1        errorLNK2019: 无法解析的外部符号

"__declspec(dllimport)public: class Poco::XML::Document * __thiscallPoco::XML::DOMParser::parse(class stlpd_std::basic_string<char,classstlpd_std::char_traits<char>,class stlpd_std::allocator<char> >const &)" (__imp_?parse@DOMParser@XML@Poco@@QAEPAVDocument@23@ABV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@@Z),

该符号在函数 "void__cdecl Mytest(void)" (?Mytest@@YAXXZ)中被引用        xmlKeyWord.obj

 

错误        2        errorLNK2019: 无法解析的外部符号 "_

_declspec(dllimport)public: __thiscall Poco::XML::InputSource::InputSource(classstlpd_std::basic_istream<char,class stlpd_std::char_traits<char> >&)"(__imp_??0InputSource@XML@Poco@@QAE@AAV?$basic_istream@DV?$char_traits@D@stlpd_std@@@stlpd_std@@@Z),

该符号在函数 "void__cdecl Mytest(void)" (?Mytest@@YAXXZ)中被引用        xmlKeyWord.obj

 

费话:

一开始我重新编译了 Poco 库, 错误依旧, 我又在Poco人提供的 Test 中 写了同样的代码, 神奇...... 没有出错,编译通过了... 我仔细比对了我的工程属性和 PocoTest的工程属性没有什么大的差别,就在此时我就要放弃它了,因为它浪费了我一个上午+1小时的时间, 我不能再折腾它了,决定博最后一把.

 

解决方案:

 我们仔细的看一下这段错误,错误分开看看:

错误        1        // 代表了你工程中的第几个错误

error LNK2019: 无法解析的外部符号 //编译器错误代码,什么错误

"__declspec(dllimport) public: class Poco::XML::Document *__thiscall Poco::XML::DOMParser::parse(classstlpd_std::basic_string<char,class stlpd_std::char_traits<char>,classstlpd_std::allocator<char> > const &)" //函数原型

(__imp_?parse@DOMParser@XML@Poco@@QAEPAVDocument@23@ABV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@@Z),// 这个签名函数(也就是名字改编后的函数名) , 注意我们要的就是这个东西

该符号在函数 "void __cdecl Mytest(void)" (?Mytest@@YAXXZ)中被引用        xmlKeyWord.obj //在哪出现的这个错误

 

 

知道签名函数后我们就去找这个签名, 错误的信息告诉我们就是在对应的lib中找不到这个签名,哪我们就去看一个对应的lib中是否有这个签名.

错误在Poco xml 库中,我们当然不是看Poco xml 的 lib 文件啦,它是个二进制文件,找起来很麻烦的. 我们可以看它的map文件. 没有的话,加上map选项 重新编译Poco xml库

有了map文件后 我们拿记事本打开它 找到 public: class Poco::XML::Document * __thiscallPoco::XML::DOMParser::parse(class stlpd_std::basic_string<char,classstlpd_std::char_traits<char>,class stlpd_std::allocator<char> >const &) 它对应该的签名,(当然了,我们这里确定是 stl 替换后的问题,所以我们 可以搜索 它前面的部分 
?parse@DOMParser@XML@Poco@@QAEPAVDocument 这样很快就找到了)

就是这一行

?parse@DOMParser@XML@Poco@@QAEPAVDocument@23@ABV?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@stlp_std@@@Z100a17a0 f   DOMParser.obj

 

我们对比一下它和我们出错的签名

 

?parse@DOMParser@XML@Poco@@QAEPAVDocument@23@ABV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@@Z

?parse@DOMParser@XML@Poco@@QAEPAVDocument@23@ABV?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@stlp_std@@@Z 100a17a0f   DOMParser.obj

 

看红色的部分 很明显我们这边多了一个d , stlp == STLProt  d==Debug

 

再想一下我们前面是不是因为boost的原因, 添加了一个 /D_STLP_DEBUG

OK 问题确定了

哪怎么让 Poco的xml库中的函数也多一个d呢, 简单也在它的工程属性中添加 /D_STLP_DEBUG

重新生成 poco xml 库 问题解决.

 

抱歉!评论已关闭.