0

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

Alexey
  • 5,898
  • 9
  • 44
  • 81
  • 2
    It all depends upon what's inside the headers, particularly the last two. You'll need to look at some of the contents of the last two includes to see what the dependency is. There might be a clue if you open `task.h` and look at line 765, and find out which of the two last headers includes `task.h`. Is `arrayfire.h` your own header file? Without revealing the contents of the headers, it would be nearly impossible for someone here to provide you a direct solution. – lurker Sep 04 '13 at 17:56
  • no arrayfire is an external library. – Alexey Sep 04 '13 at 17:57
  • OK, but my other suggestion still applies. Also check documentation on the library/headers. Is there a reason why you need to swap the headers around? There could be a known dependency where they must be in the order that actually works. – lurker Sep 04 '13 at 17:57
  • Perhaps you could show us line 765 of `tbb/task.h`, and a few lines around it? That might help us guess the problem. – Mike Seymour Sep 04 '13 at 17:59

1 Answers1

4

This is caused by the following evil in one of the ArrayFire headers:

#define group(...)  __VA_ARGS__

This defines a function-like macro that is replaced by the list of macro arguments; group(a,b) expands to a,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:

task_group_context* group () { return prefix().context; }

converting it to

task_group_context* { return prefix().context; }

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.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644