A way How to Compile C library into .Net dll?

前端 未结 4 1211
别那么骄傲
别那么骄傲 2021-01-05 23:22

Can we compile C library as .Net dll (containing and opening access to all C libs functions) by just compiling cpp project containing code like

extern \"C\"         


        
4条回答
  •  广开言路
    2021-01-06 00:03

    It's not generally a given that you can even compile C code as C++ without making some changes. If you can get your C code to compile as C++, then you can try getting it to compile as C++/CLI (that's what the clr:pure option does).

    At that point, you can create some kind of class which exposes all your exported functions as static methods of a public (managed) class.

    Some flavours of this sort of stuff can be done with C++ preprocessor tricks (macros, etc), sometimes you end-up writing wrappers manually.

    So the basic information that you can compile C++ into .NET assemblies using /clr:xxx options is true, but that doesn't mean it's the only thing you need to do to get a useful .NET assembly.

提交回复
热议问题