Kosuha

Hi !

I got very strange problem of being unable to compile c++ console project which is using OpenMP directives in its code.

The problem is that OpenMP was supposed to be added to a big project which is being developed but I met following compiler error:

code (gives error even in such simple form):

#pragma omp parallel

{

#pragma omp for

for (int i = 0; i < 10; i++)

{

// some code:

}

}

error:

4>------ Build started: Project: _LogonServer, Configuration: DebugOpenMP Win32 ------

4>Compiling...

4>app_ls.cpp

4>.\app_ls.cpp(78) : error C3001: 'if' : expected an OpenMP directive name

I am surprised with error description: "if" : expected an OpenMP directive name, where no 'if' was used, and thus I suppose compiller makes mistake.

If I create new VC 8.0 C++ project and enable /openmp, all compiles just fine.

The one project which gives this error was first being developed under 7.1 VC++ and later was converted to 8.0 VC++, do not know if it matters.

#include <omp.h> was also added to cpp module where OpenMP code was used.

Are any ideas why such compiler behaviour could be

Regards,

Dmitry.



Re: Visual C++ General Unknown/not-understandable compiler error using OpenMP directives

Kosuha

Would anyone give any suggestion Please.



Re: Visual C++ General Unknown/not-understandable compiler error using OpenMP directives

Holger Grund

I'm afraid, I can't really think of anything that would that diagnostic. However, you could try to preprocess your code and take another look (also make sure you have correct line-endings)

Can you show us the preprocessed code and tells us in which line the diagnostic occurs

-hg





Re: Visual C++ General Unknown/not-understandable compiler error using OpenMP directives

Kosuha

Ok, made example function inside one of CPP files of the project:

static void Example()

{

#pragma omp parallel

{

#pragma omp for

for (int x = 0; x < 10; x++)

{

}

}

}

The preprocessing result if to compile this CPP file alone:

static void Example()

{

#pragma omp parallel

{

#pragma omp if(true) for

if(true) for (int x = 0; x < 10; x++)

{

}

}

}

I started to review project defines and found one of following defines which made the problem:

// fix buggy MSVC's for variable scoping to be reliable =S

#define for if(true) for

As we are team of coders it was difficult to find right cause of error. The preprocessing result is now:

static void Example()

{

#pragma omp parallel

{

#pragma omp for

for (int x = 0; x < 10; x++)

{

}

}

}

Which is fully correct now!

Thank you very much for a hint which led to bug fix!

Best regards,

Dmitry.





Re: Visual C++ General Unknown/not-understandable compiler error using OpenMP directives

Holger Grund

Glad to hear the issue is resolved. Re for loop scoping, at some point (7.0 ) /Zc:forScope was an opt-in mechanism for standard conformant scoping. In 8.0 (and 7.1 IIRC) it's on by default and you can opt out with /Zc:forScope- (BTW: Same goes for wchar_t)

-hg





Re: Visual C++ General Unknown/not-understandable compiler error using OpenMP directives

Ramkrishna Pawar

Have yo enabled OMP support

/openmp (Enable OpenMP 2.0 Support) (C++)