为什么我在iterator_facade中得到编译错误取决于我把我的Boost头包含在哪里
Why do I get compilation errors in iterator_facade depending on where I put my Boost header includes?
我正在尝试将Boost合并到我现有的中型项目中。我有预编译的头文件,stdafx.h
,在那里我保留了所有的c++标准库#include
指令(加上一些Windows头文件),以及许多.cpp
文件,其中包括stdafx.h
,其中A.cpp
。它在第一行包含stdafx.h
,然后仅包含该文件所需的一些其他头文件。我想在A.cpp
中使用boost::program_options
,所以我把它添加到stdafx.h
之后的包含列表中,所以A.cpp
的顶部看起来像这样:
#include "stdafx.h"
#include <boost/program_options.hpp>
// more #includes
然后我开始编译这个项目,但是遇到了以下错误:
Severity Code Description Project File Line
Error C2976 'boost::iterators::detail::postfix_increment_result': too few template arguments testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 789
Error C1903 unable to recover from previous error(s); stopping compilation testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 790
Error C2143 syntax error: missing ';' before '++' testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 790
Error C2059 syntax error: ',' testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 534
Error C2059 syntax error: ',' testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 541
Error C2059 syntax error: ',' testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 600
Error C2059 syntax error: ',' testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 606
Error C2059 syntax error: ',' testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 789
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 790
Error C2433 'type': 'inline' not permitted on data declarations testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 790
Error C2888 'if_<T1,T2,T3>::type type': symbol cannot be defined within namespace 'iterators' testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 790
Error C2976 'boost::iterators::iterator_facade': too few template arguments testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 534
Error C2976 'boost::iterators::iterator_facade': too few template arguments testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 541
Error C2976 'boost::iterators::iterator_facade': too few template arguments testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 600
Error C2976 'boost::iterators::iterator_facade': too few template arguments testProject C:boost_1_59_0boostiteratoriterator_facade.hpp 606
我做了一些实验,发现如果我把
#include <boost/program_options.hpp>
在stdafx.h
的非常末尾——最后一行——一切都编译得很好,但是如果我试图把它放在A.cpp
的任何地方,我得到了上面的错误。我真的不明白这是怎么可能的;难道预处理器不只是执行无意识的插入,在这种情况下,在预处理器完成其工作后,应该将相同的输出提供给编译器?原因是什么呢?我已经搜索过了,但我只发现了那些实际上想要使用iterator_facade
的人的帖子,并且在他们的代码中得到错误,而不是在Boost头中。
我的配置:VS 2015 on Windows 8.1, Boost 1.59.0, x86项目,使用/MT
构建
UPDATE:如果我在A.cpp
和stdafx.h
中都包含该头文件,它也可以工作。
UPDATE2:有趣的是,这是编译失败后我在输出窗口中的内容:
1> INTERNAL COMPILER ERROR in 'C:Program Files (x86)Microsoft Visual Studio 14.0VCbinCL.exe'
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
最可能的解释是,您的一个头文件缺少包含保护(或包含保护有一个打字错误),而您实际上包含了一些boost头文件两次。(不是所有的boost头文件都单独包含了守卫。你应该包括的那些,但其中一些只是没有"出于效率的原因"我被告知。
或者,您在某个命名空间中包含boost,这是它无法真正保护自己的事情。
这个错误'boost::iterators::detail::postfix_increment_result': too few template arguments
正是我所期望的,如果它是一些模板定义和编译器第二次遇到定义。
- 我的神经网络不起作用 [XOR 问题]
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 我的字符计数代码计算错误.为什么
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- cmake在我的项目中所需的所有静态库都不成功
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 为什么我的for循环不能正确获取argv
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 0-1背包代码中的错误.我的代码中有什么错误
- 当我的阵列太大时出现分段错误
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 为什么二进制搜索在我的测试中不起作用
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- 求解未校正序列 (4,3,2,1,5) 并将其更改为校正序列取决于我的建议
- 如何设置我的dll加载,该dll取决于Env-ailiable的某些第三部分DLL
- 为什么我的二进制大小取决于我的数组的大小
- 为什么我在iterator_facade中得到编译错误取决于我把我的Boost头包含在哪里