一种方法如何编译C库到NET的DLL? [英] A way How to Compile C library into .Net dll?

查看:141
本文介绍了一种方法如何编译C库到NET的DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以通过只编译包含code像

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" {
#include <library.h>
}

/ CLR:纯与VS 的说法? (VS10)

with /clr:pure argument with VS? (VS10)

或者我们应该做些更trickey?

Or we should do something more trickey?

推荐答案

我觉得这是最好的使用旧式托管C ++这一点。

I found it is the best to use the old style Managed C++ for this.

CLR:PURE 只是不会削减它

例如:

extern "C" int _foo(int bar)
{
  return bar;
}

namespace Bar
{
  public __gc class Foo
  {
  public:
    Foo() {}

    static int foo(int bar)
    {
      return _foo(bar);
    }
  };
};

与编译: / CLR:oldSyntax

现在,你可以参考assebmly,并调用 Bar.Foo.foo()从.NET。

Now you can reference the assebmly, and call Bar.Foo.foo() from .NET.

这篇关于一种方法如何编译C库到NET的DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆