compilation in visual c++

Has anybody tried to compile an OpenLB example in VC++ ? I did it and I get errors like

\openlb\core\dynamics.hh(55) : error C2244: ‘olb::Dynamics<T,Lattice>::iniEquilibrium’ : unable to match function definition to an existing declaration
c:\sim\producers\producers\openlb\core\dynamics.h(66) : see declaration of ‘olb::Dynamics<T,Lattice>::iniEquilibrium’
‘void olb::Dynamics<T,Lattice>::iniEquilibrium(olb::Cell<T,Lattice> &,T,const T [Lattice::d])’
existing declarations
‘void olb::Dynamics<T,Lattice>::iniEquilibrium(olb::Cell<T,Lattice> &,T,const T [Lattice::d])’

As you can see, the compiler does not find the declarations of the methods even though he has found them. Strange.

Is it because the methods have template arguments like
template<typename T, template class Lattice>
I haven’t seen those before and I’m not sure whether they are valid for the VC++ compiler.

Or is it impossible to compile OpenLB under VC++ at all?


No, we have never tried compiling OpenLB with VC++. But although it is difficult to be sure of such a thing, I do believe that the OpenLB code is compatible with the ISO C++ standard, and I also think that VC++ implements this standard properly. In particular, I would be surprised if the compiler had difficulties parsing template declarations.

Here are a few suggestions:

  • Try to use a recent version of VC++. It is likely that VC6 and older don’t work, as they were not entirely standard compatible.
  • Is there a flag by which you can enforce ISO C++ compatibility, as opposed to Microsoft’s “Managed C++” version?
  • You may need to comment all lines beginning with the word “system” in the file “imageWriter.hh”, because these lines rely on the presence of a POSIX complying platform, which Windows is not.

In case you success with compiling OpenLB under VC++, it would be great if you could post a short summary on how you did.

I was looking for solution of this problem and it seems like it’s a bug in visual studio that was introduced with service pack 1 to vs 2005.
I have vs 2008 and it doesn’t work here too.
There seems to be some fix to vs 2005 - KB930198 but I don’t know if it works.

Hi toczka,

Have you solved your problem in the meantime? I am also trying to run OpenLB in Visual Studio 9.0 und I am running into the same error…

Hi tczka, Hi smeier,

using the sample cylinder2d.cpp add the following #define


#include “olb2D.h”
#ifndef OLB_PRECOMPILED // Unless precompiled version is used,
#include “olb2D.hh” // include full template code

Only .h is used now

@dirk1000: This does not solve the problem, since creating the olb-library using the VC compiler gives similar errors.

I found out that the VC compiler doesn’t like class templates, where the member functions pass arrays as arguments, when the array size depends on the template class. That’s exactly the case for the member function:

void olb::Dynamics<T,Lattice>::iniEquilibrium(olb::Cell<T,Lattice> &cell,T rho, const T u[Lattice::d])

The problem seems to be that the array parameter const T u[Lattice::d] has unknown size at compile time. Therefore, the VC compiler is not able to link the definition to its correct declaration. Really strange…

I guess a possible fix could be to replace the function declaration and definition by :

void olb::Dynamics<T,Lattice>::iniEquilibrium(olb::Cell<T,Lattice> &cell,T rho, const T *u)

The problem is that this issue appears at many places in the code, mostly in the classes related to Momenta and Dynamics. I did not try out if this is a valid solution in all cases.

By the way, what is the reason for copying the whole arrays in these member functions? Would a call-by-reference or by pointer not be more efficient?

We have unfortunately never managed to compile OpenLB with VC++. It is difficult to say which one of the two is not standard compliant, whether it’s VC++ or OpenLB, because the standard is really complicated. But for the time being we rather try to be compliant with the compilers which are common in high performance computing.

I don’t think that the parameter u is copied in the following line:

void olb::Dynamics<T,Lattice>::iniEquilibrium(olb::Cell<T,Lattice> &cell,T rho, const T u[Lattice::d])

If I am not mistaken, this line is essentially equivalent to

void olb::Dynamics<T,Lattice>::iniEquilibrium(olb::Cell<T,Lattice> &cell,T rho, const T * u)

This is something you can check by removing the const and modifying the value of u inside the function. You will see that u is modified outside the function too, which shows that the parameter was transferred with reference semantics, and not copy semantics.

Hi jlatt,

of course you are right with the array passing, I was wrong.

For the moment, I will go on working with gcc compiler using cygwin. However, if someone has other experience with the VC++ compiler, it would be great to post it here.

It 's possible to compile Palabos in VS2008 with installed Intel C++.
What about VS C++ compiler error C2244, there are some explanation on MSDN