Search code examples
c++visual-studio-2010c++-clicommand-line-interfaceeigen

Mysterious C++/CLI managed/unmanaged Error with Eigen


I'm working with an existing Visual Studio 2010 project, where I'm now supposed to add new functionality (Eigen and Point Cloud Library) into an existing method (let's call it foo()). I now that the project is using C++/CLI somehow. I have to admit I have no clue about C++/CLI, just read a little bit about it. However the class where foo() is declared and defined seems to be a regular C++ class, no ref or any other CLI identifier. But within foo() Handles (var^) are used. So I'm not quite sure if foo() is a managed function!? I can add pretty much regular C++ code to this function, but now I started with Eigen and PCL and a discovered some mysterious errors. For example, when I'm declaring this:

 Eigen::Matrix3f m;

Everythings working fine. But when I'm doing this:

 Eigen::Matrix4f m;

I get the following errors:

error C2711: 'fooclass::foo' : this functon cannot be compiled as managed, consider using #pragma unmanaged 
error C3821: 'void fooclass::foo(void)': managed type or function cannot be used in an unmanaged function

So it is working with 3f but not with 4f! That is so strange and it's just one example. I can not recognize any pattern. In my understanding VS somehow thinks that Matrix4f is a managed function.

I would appreciate any tip! I don't even know where to start looking.


Solution

  • I don't know anything about CLI, but the only significant difference between Matrix3f and Matrix4f is that the second is vectorized and internally its data is requested to be aligned with __declspec(align(16)).