有人使用 CLI 后端为 gcc 编译器编译 lib x264 吗?

发布于 2024-09-08 20:45:26 字数 138 浏览 3 评论 0原文

有没有人使用 gcc 的 CLI 后端 编译器编译 lib x264? (将x264编译成.net dll)

Has any one compiled lib x264 using CLI backend for gcc compiler? (Compiled x264 into .net dll)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泅渡 2024-09-15 20:45:26

您使用 C99 功能吗?如果没有,带有 /clr:pure 选项的 Visual C++ 应该可以解决问题。您将需要混合一点 C++/CLI 来定义其他 .NET 项目可以调用的入口点,但这些可以位于完全独立的文件中(您可以与本机项目共享整个纯 C 源文件)。

编辑:完成此工作的基本指南:

  • 在 Visual Studio 中,创建一个 C++/CLI 类库项目
  • 将所有 C 源文件添加到项目
  • 中 在项目配置中,设置包含路径,以便找到标头
  • 在项目配置中,还设置“使用公共语言运行时”到 /clr:pure
  • 在新项目向导创建的 .cpp 文件中,为您创建函数原型的头文件添加 #include 指令想要使用。
  • 在新项目向导创建的 ref class 中(在上述 .cpp 文件中),添加一些调用 C 库函数的函数(可能是静态函数)。
  • 编译,添加此 .DLL 作为 C# 项目的引用,并享受

作为提示,您可能希望创建函数,而不是在 ref class 中为库中的每个函数创建转发函数通过调用一堆库函数来完成有用的工作(对于对您的特定项目有用的特定定义)。

您可能希望熟悉 marshal_as 模板,该模板非常适合将 .NET System::String 转换为 C 字符串,然后再转换回来。

Are you using C99 features? If not, Visual C++ with the /clr:pure option should do the trick. You will need a little bit of C++/CLI mixed in to define your entrypoints that other .NET projects can call, but those can be in completely separate files (you can share entire C-only source files with native projects).

EDIT: Basic guide to making this work:

  • In Visual Studio, create a C++/CLI Class Library project
  • Add all your C source files to the project
  • In Project Configuration, set the include path so your headers are found
  • In Project Configuration, also set "Use of Common Language Runtime" to /clr:pure
  • In the .cpp file created by the new project wizard, add #include directive for the header files which prototype the functions you want to use.
  • In the ref class created by the new project wizard (in the aforementioned .cpp file), add some functions (maybe static functions) which call your C library functions.
  • Compile, add this .DLL as a reference of your C# project, and enjoy

As a hint, instead of creating a forwarding function in the ref class for every function in the library, you may want to make functions that do useful work (for the particular definition of useful for your particular project) by calling a bunch of library functions.

You'll probably want to get comfortable with the marshal_as template which is good for converting .NET System::String into C strings and back again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文