由于头文件中的语法错误,导致编译错误
Compile error due to syntax error in header file
我有一个依赖于几个include文件的程序。当我按照下面显示的顺序定义includes时,程序编译得很好。
#include <iostream>
#include "opencv2/cvconfig.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/internal.hpp" // For TBB wrappers
#include "arrayfire.h"
然而,当我切换最后两个时,包括如下所示
#include <iostream>
#include "opencv2/cvconfig.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "arrayfire.h"
#include "opencv2/core/internal.hpp" // For TBB wrappers
我得到编译器错误:
1> d:\libraries\tbb41\tbb41_20130613oss\include\tbb\task.h(765):错误C2059:语法错误:"{"1> d:\libraries\tbb41\tbb41_20130613oss\include\tbb\task.h(765):错误C2334:"{"之前的意外令牌;正在跳过明显的函数机身
这是出乎意料的,我想修复它。所有的include都来自库(OpenCV和ArrayFire)。关于可能的原因以及如何解决这个问题,有什么建议吗?
编辑这是任务的相关部分。h:
759 #if __TBB_TASK_GROUP_CONTEXT
760 //! This method is deprecated and will be removed in the future.
761 /** Use method group() instead. **/
762 task_group_context* context() {return prefix().context;}
763
764 //! Pointer to the task group descriptor.
765 task_group_context* group () { return prefix().context; }
766 #endif /* __TBB_TASK_GROUP_CONTEXT */
在第765行中,IDE抱怨{
,称Error: expected an identifier
这是由其中一个ArrayFire标头中的以下邪恶引起的:
#define group(...) __VA_ARGS__
这定义了一个类似函数的宏,该宏被宏参数列表所取代;group(a,b)
扩展到a,b
,(这里更重要的是)group()
扩展到零。由于宏不尊重范围等语言级别的概念,这会干扰后面的声明:
task_group_context* group () { return prefix().context; }
将其转换为
task_group_context* { return prefix().context; }
这不是一个有效的声明。
修复方法是最后包含"arrayfire.h"
,并注意在自己的代码中尝试使用哪些名称;或者在包括它之后对#undef group
(以及它可能犯下的任何其他邪恶)。或者,如果可能的话,用火杀死它,用一些不那么邪恶的东西代替。
相关文章:
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- std::is_base_of表示ctor编译错误
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- Qt Cmake 错误编译"GuiSupportQt not found"
- Opengl 精度转换错误编译错误 E0415
- 库将ARM架构错误编译为架构X64
- RT 音频 Mac 错误 g++ 编译错误
- 错误编译Boost.log
- 错误编译QT创建者 / QT窗口小部件示例
- 错误编译MIPS32
- Visual Studio 2013 中的错误(编译和运行代码)
- 链接错误编译qt项目在visual 2010
- 无法用模板错误编译nsgmls
- 奇怪的错误.编译失败
- 如果有人调用c++中的方法,则强制错误(编译时)
- 来自autoconf测试的错误编译命令
- 时间限制超出错误C++编译
- SFML 2.3 和 CodeBlocks 错误编译