我正在尝试修复一个开源C++项目中的一些错误,而原作者目前正在忙于他的学术生活来提供帮助.gcc-4.9通过macports安装代码编译得很好.我一直lldb在命令行上进行调试.但是,如果可能的话,我想获得编译的代码,clang因为这样我就可以使用Xcode lldb并使bug更容易隔离.
当我尝试编译代码时clang,我收到以下错误:
In file included from ./src/include/hash.h:25:
./src/include/hash_stream.h:18:11: error: call to function 'operator>>' that is neither visible in the template definition
nor found by argument-dependent lookup
iss >> table[key] ;
^
./src/common/tagger/implementations/collins/tagger.h:118:9: note: in instantiation of function template specialization
'operator>><CWord, english::CTag>' requested here
i >> (*m_TopTags);
^
./src/english/tags.h:29:23: note: 'operator>>' should be declared prior to the call site or in namespace 'english'
inline std::istream & operator >> (std::istream &is, english::CTag &tag) {
^
1 error generated.
make: *** [obj/english.postagger.o] Error 1
Run Code Online (Sandbox Code Playgroud)
此文件中出现此错误,该文件基本上是尝试读取键,a :和由空格分隔的值到自定义哈希映射中.我已经阅读了clang兼容性指南中的相关部分,但我无法弄清楚我需要更改以便进行编译.
编辑:每个@ms,我修改src/common/tagger/implementations/collins/tagger_include.h为移动到tags.h上面hash_stream.h,似乎解决了这个错误.但是,我现在遇到一个新错误:
In file included from ./src/common/conparser/implementations/muhua/weight.cpp:13:
In file included from ./src/common/conparser/implementations/muhua/weight.h:13:
In file included from ./src/common/conparser/weight_base.h:13:
In file included from ./src/common/conparser/base_include.h:10:
In file included from ./src/english/tags.h:43:
In file included from ./src/english/pos/penn_morph.h:15:
In file included from ./src/include/knowledge/tagdict.h:15:
In file included from ./src/include/hash.h:25:
./src/include/hash_stream.h:15:11: error: call to function 'operator>>' that is neither visible in the template definition
nor found by argument-dependent lookup
iss >> key;
^
./src/include/learning/perceptron/hashmap_score_packed.h:282:7: note: in instantiation of function template specialization
'operator>><std::__1::pair<unsigned long, unsigned long>, CPackedScore<double, 2048> >' requested here
is >> static_cast< CHashMap< K, CPackedScore<SCORE_TYPE, PACKED_SIZE> > &>(score_map) ;
^
./src/common/conparser/implementations/muhua/weight.cpp:48:27: note: in instantiation of function template specialization
'operator>><std::__1::pair<unsigned long, unsigned long>, double, 2048>' requested here
iterate_templates(file >>,;);
^
./src/common/conparser/implementations/muhua/weight.h:133:4: note: expanded from macro 'iterate_templates'
left(m_mapS0cmN0tm)right\
^
./src/include/pair_stream.h:16:16: note: 'operator>>' should be declared prior to the call site
std::istream & operator >> (std::istream &is, std::pair<T1, T2> &p) {
^
1 error generated.
make: *** [obj/english.conparser/weight.o] Error 1
Run Code Online (Sandbox Code Playgroud)
我试图包括pair_stream.h之前,hash.h但似乎没有工作,我再次难过.任何帮助将非常感激.
编辑2:我实际上考虑过事情并再次尝试,现在一切正常.感谢大家!StackOverflow太棒了:)
正如错误消息所述,std::istream & operator >> (std::istream &is, english::CTag &tag)定义于src/english/tags.h.但是,由于src/include/hash_stream.h包含在该文件之前声明它的模板,因此会发生错误.
文档已经提供了解决方案:
确保在可能调用它的模板之前声明要调用的函数.如果它的参数类型都不包含类,则这是唯一的选项.您可以通过移动模板定义,或移动函数定义,或在模板之前添加函数的前向声明来执行此操作.
因此,要么确保该文件包含之前包括src/include/hash_stream.h,或申请任何由文档所提供的解决方案.
| 归档时间: |
|
| 查看次数: |
3715 次 |
| 最近记录: |