3
votes

I have created a C++/CLI wrapper around some library. When I inspect the compiled assembly in one of the freely available decompilers, apart from pure managed classes and namespaces I see a plethora of unmanaged pure C++ classes and namespaces. I see no point in having them there.

Is there a way to get rid of them and show only pure managed stuff? This is a question of pure aesthetics, nothing more.

2

2 Answers

4
votes

It is a lot more than just esthetics, you are apparently compiling native code to IL instead of machine code. The C++/CLI compiler is very good at compiling native C++ code to IL, almost anything is supported. What you get is however inefficient, you don't get the benefit of the code optimizer that can take its merry time inside the compiler to generate optimized machine code. The .NET just-in-time compiler has an optimizer too but it can't do quite the same job.

Fix this by applying the /clr option only to individual source code files. Or you can do it in source code with the #pragma managed directive.

2
votes

I think you would want to create an non-mixed assembly, then. Read up on the different 'flavours' of C++/CLR libraries:

  • Mixed (/clr)
  • Pure (/clr:pure)
  • Safe (/clr:safe)

In particular, you seem to be after /clr:safe which is the most restrictive output format and results in assemblies, just as created with e.g. C# or VB.Net

Mixed, Pure, and Verifiable Feature Comparison