gpt4 book ai didi

c++ - 无法使用 clang 编译代码,但可以使用 gcc

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:30:43 27 4
gpt4 key购买 nike

我正在尝试修复一个开源 C++ 项目中的一些错误,而原作者目前忙于他的学术生活而无法提供帮助。通过 macports 安装的 gcc-4.9 代码编译得很好。我一直在命令行上使用 lldb 进行调试。但是,如果可能的话,我希望使用 clang 编译代码,因为这样我可以同时使用 Xcode 和 lldb 并使错误更容易隔离。

当我尝试使用 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文件,它基本上试图读取一个键、一个 : 和一个由空格分隔的值到自定义 HashMap 中。我已阅读相关section在 clang 兼容性指南中,但我无法弄清楚我需要更改什么才能编译它。

编辑:根据@m-s,我修改了src/common/tagger/implementations/collins/tagger_include.h 以移动tags.hhash_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

我试图在 hash.h 之前包含 pair_stream.h 但这似乎不起作用,我又被难住了。任何帮助将非常感激。

编辑 2:我实际上考虑了一些事情并再次尝试了这个,现在一切正常了。感谢大家! StackOverflow 很棒 :)

最佳答案

如错误消息所述,std::istream & operator >> (std::istream &is, english::CTag &tag)src/english/tags.h 中定义。但是由于调用它的 src/include/hash_stream.h 中的模板是在包含该文件之前声明的,所以会发生错误。

文档已经给出了解决方案:

Make sure the function you want to call is declared before the template that might call it. This is the only option if none of its argument types contain classes. You can do this either by moving the template definition, or by moving the function definition, or by adding a forward declaration of the function before the template.

因此,要么确保在包含 src/include/hash_stream.h 之前包含此文件,要么应用文档提供的任何解决方案。

关于c++ - 无法使用 clang 编译代码,但可以使用 gcc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31036530/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com