Ubuntu Eclipse G++编译出错?
错误信息 1:make:***[workspace/project/****.o] Error1.
错误信息 2 : no match for ‘operator<’ in ‘__first2.std::_List_iterator<_Tp>::operator* [with _Tp = CSimpleIniTempl<char, SI_GenericNoCase<char>, SI_ConvertA<char> >::Entry, std::_List_iterator<_Tp>::reference = CSimpleIniTempl<char, SI_GenericNoCase<char>, SI_ConvertA<char> >::Entry&]() < __first1.std::_List_iterator<_Tp>::operator* [with _Tp = CSimpleIniTempl<char, SI_GenericNoCase<char>, SI_ConvertA<char> >::Entry, std::_List_iterator<_Tp>::reference = CSimpleIniTempl<char, SI_GenericNoCase<char>, SI_ConvertA<char> >::Entry&]()’.
求路过的大婶大叔、大哥大姐给点儿指点,我以为是G++编译选项设置有问题,比如 -frepo 什么的,但是试过了能找到的全部选项,都无济于事!这都是什么错误呢? Ubuntu Eclipse G++ 编译出错 .o生成失败
[解决办法]
你说 "被报错的那个文件我之前在我的Qt程序中使用过,完全是没有问题的",那把文件内容帖上来,要是太长就算了。
查了一下 g++-4.7.0(手头没有 4.6) list.tcc line 305,是这个
if (*__first2 < *__first1)
是 list::merge 函数的一部分,对 list::iterator 解引用后得到的对象类型无法用 operator< 比较大小。后者具体是 CSimpleIniTempl<char,SI_GenericNoCase<char>,SI_ConvertA<char>>::Entry.
从来没用过这个,上网翻了翻,这个网页给了文档,
http://code.jellycan.com/simpleini-doc/html/class_c_simple_ini_templ.html
然后这里 line 297 给了 Entry 的具体定义。
http://code.jellycan.com/simpleini-doc/html/_simple_ini_8h_source.html
后者包含了这么一句坑爹的条件编译
00320 #if defined(_MSC_VER) && _MSC_VER <= 1200
00321
00322 bool operator<(const Entry & rhs) const { return LoadOrder()(*this, rhs); }
00323 bool operator>(const Entry & rhs) const { return LoadOrder()(rhs, *this); }
00324 #endif
我想这也解释了为什么到 g++ 就水土不服了,因为这家伙的 operator< 只给 ms 用。
不过源码说的也很清楚,operator< 无非就是 LoadOrder()(*this, rhs);,所以去你的源文件(EditPartnerIni?),找到那里(间接)调用的 list::merge,然后修改一下,调用另一个接受比较对象的重载,把 LoadOrder 传进去作为比较标准。
至于为什么 #if defined(_MSC_VER) && _MSC_VER <= 1200 享有特殊待遇,因为 vc6.0 的 list::merge 接受比较函数的实现有 bug,一编译就出错。