c – 无法使用clang编译代码,但可以使用gcc
我正在尝试修复一个开源C项目中的一些错误,原作者目前忙于他的学术生活来帮助.通过macports安装
gcc-4.9,代码编译得很好.我一直在命令行上使用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 在this文件中发生此错误,该文件基本上是尝试读取密钥,a:和由空格分隔成自定义哈希映射的值.我已经在clang兼容性指南中阅读了相关的section,但我无法弄清楚我需要更改以进行编译. 编辑:Per @ m-s,我修改了src / common / tagger / implementation / 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,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 我试图在hash.h之前包含pair_stream.h,但这似乎不起作用,我再次难过.任何帮助将非常感激. 编辑2:我实际上考虑过事情并再次尝试,现在一切正常.感谢大家! StackOverflow太棒了:) 解决方法
正如错误消息所述,std :: istream&运算符>> (std :: istream& is,english :: CTag& tag)在src / english / tags.h中定义.
但是,由于在包含该文件之前声明了调用它的src / include / hash_stream.h中的模板,因此会发生错误. 文档已经提供了解决方案:
因此要么在包含src / include / hash_stream.h之前确保包含此文件,要么应用文档提供的任何解决方案. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |