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

前端 未结 4 1245
别那么骄傲
别那么骄傲 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-05 23:38

    It really depends on your C code.

    P/Invoke is often the easiest to start with, and IMO is pretty workable for a handful of functions. Performance isn't necessarily great, and I wouldn't construct an entire program out of it - but to reuse some functions, it's worthwhile.

    Going from C to /clr:pure requires you to:

    1. Convert your C code to C++
    2. Convert your C++ code to Visual C++
    3. Compile with /clr option
    4. Compile with /clr:pure

    The current state of your code (and it's libraries) will dictate how painful that process is.

提交回复
热议问题