I have a program that relies on several include files. When I define includes in the order shown below the program compiles fine.
#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"
However, when I switch the last two includes as shown below
#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
I get compiler errors:
1>d:\libraries\tbb41\tbb41_20130613oss\include\tbb\task.h(765): error C2059: syntax error : '{' 1>d:\libraries\tbb41\tbb41_20130613oss\include\tbb\task.h(765): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
This is unexpected and I'd like to fix it. All of the includes are from libraries (OpenCV and ArrayFire). Any suggestions on what may be the cause and how to fix this issue?
Edit Here's the relevant part of task.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 */
In line 765, the IDE complains about {
, saying Error: expected an identifier
This is caused by the following evil in one of the ArrayFire headers:
This defines a function-like macro that is replaced by the list of macro arguments;
group(a,b)
expands toa,b
, and (more importantly here)group()
expands to nothing. Since macros have no respect for language-level concepts like scopes, this interferes with the later declaration:converting it to
which is not a valid declaration.
The fix is to include
"arrayfire.h"
last, and be careful which names you try to use in your own code; or to#undef group
(and any other evil it might perpetrate) after including it. Or, if possible, kill it with fire and use something less evil instead.