将 FreeType 编译为 DLL(与静态库相反)

发布于 2024-11-12 22:49:21 字数 367 浏览 8 评论 0原文

我想在 ac# 项目中使用 FreeType。我找到了这个 绑定,但我仍然需要一个 freetype.dll。我通常在我的 C++ 项目中使用静态库,所以我从未编译过。打开 freetype-solution (VS2010),我注意到没有动态库的配置 - 只有静态库。我尝试进行自己的配置并让它生成 freetype.dll。如果我将它与 c# 绑定一起使用,则会出现异常,即未找到 FT_Init_FreeType 入口点。知道我必须如何调整 freetype-project 才能导出这些函数吗?

I want to use FreeType in a c# project. I found this binding, but I still need a freetype.dll. I usually use a static library in my c++ projects, so I never compiled one. Opening the freetype-solution (VS2010) I noticed that there is no configuration for a dynamic library - just static ones. I tried to make my own configuration and got it to generate a freetype.dll. If I use it with the c#-binding I get an exception, that the FT_Init_FreeType-entry point was not found. Any idea how I must adjust the freetype-project in order to export those functions?

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

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

发布评论

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

评论(3

幽蝶幻影 2024-11-19 22:49:21

如果您可以使用旧版本(2008 年 3 月),您可以访问 FreeType for Windows< /a>页面,下载最新的Binaries包,打开.ZIP,并从bin目录中解压FreeType6.dll。只需适当重命名即可。

如果您需要更新的版本,可以通过以下方式编译最新版本:

  • http://sourceforge.net/projects/freetype/files/freetype2/

  • 打开 Visual Studio 2010,然后从 builds\win32\vc2010 目录加载 freetype.sln

  • 打开项目配置,然后在常规选项卡中,将配置类型更改为动态库(.dll)

  • 打开ftoption .h 文件,并添加以下行(例如“DLL 导出编译”备注部分附近):

    <前><代码>#define FT_EXPORT(x) __declspec(dllexport) x
    #define FT_BASE(x) __declspec(dllexport) x

  • 将项目编译配置更改为“

  • 编译项目。现在,objs\win32\vc2010 目录中应该有一个 freetype246.dll

If you're ok with an old version (march 2008), you can go to FreeType for Windows page, download the latest Binaries package, open the .ZIP, and extract FreeType6.dll from the bin directory. Just rename it appropriately.

If you need a more recent version, here is how you can compile the latest:

  • download the latest source (2.4.6 as of today) from http://sourceforge.net/projects/freetype/files/freetype2/

  • open Visual Studio 2010, and load freetype.sln from the builds\win32\vc2010 directory.

  • open the project config, and in the General tab, change Configuration Type to Dynamic Library (.dll)

  • open the ftoption.h file, and add these lines (near the "DLL export compilation" remarks section for example):

    #define FT_EXPORT(x)  __declspec(dllexport) x
    #define FT_BASE(x)    __declspec(dllexport) x
    
  • change the project compilation configuration to "Release".

  • compile the project. You should now have a freetype246.dll in the objs\win32\vc2010 directory.

噩梦成真你也成魔 2024-11-19 22:49:21

我敢打赌,问题在于您的 DLL 项目不导出任何符号,因此虽然所有代码都在其中,但符号的地址不在导出表中,因此没有人可以从外部访问它们。

这个问题有一个很好的解决方案,可以导出 . dll,而无需手动列出它们。

I'm going to bet that the problem is that your DLL project does not export any symbols, so while all the code is in there the addresses of the symbols are not in the exports table so nobody can get to them from the outside.

This question has a nice solution to export all the symbols in a .dll without having to manually list them.

叶落知秋 2024-11-19 22:49:21

未来在这里。这是写给该主题的未来读者的。

FT2支持创建静态和动态库。他们有预制的解决方案,可以在 builds 目录中找到。

如果您被迫使用 CMAKE,您将必须执行已接受的答案的操作。然而,它不再是当前的。我无法找到引用 dll 的所述文件(例如在“DLL 导出编译”备注部分附近):。它现在位于第 424 行附近的 freetype-xxx\include\freetype\config\ftconfig.h。我使用的是 MSVS 2017,因此请尝试遵循。

mkdir build
cd build
cmake -G "Visual Studio 15 2017 Win64" ..

打开 freetype-xxx\include\freetype\config\ftconfig.h 并在第 424 行左右,修补 __declspec(dllexport) 的位置:

...
  /* You can provide your own implementation of `FT_EXPORT` and        */
  /* `FT_EXPORT_DEF` here if you want.                                 */
  /*                                                                   */
  /* To export a variable, use `FT_EXPORT_VAR`.                        */
  /*                                                                   */

// This is due to FT_EXPORT and FT_BASE not generating a .lib file, just a .dll
#ifdef FT_EXPORT
#undef FT_EXPORT
#define FT_EXPORT(x)  __declspec(dllexport) x
#endif

#ifdef FT_BASE
#undef FT_BASE
#define FT_BASE(x)    __declspec(dllexport) x
#endif

#ifndef FT_EXPORT
...

打开 CMAKE 生成的解决方案,名为自由类型.sln。在类视图中选择 freetype。项目->属性->一般->目标扩展 ->设置为 .dll 并在 Project Defaults -> 下配置类型->设置为Dynamic Library (.dll)

确保选择Release 并Build ->构建自由类型。在包含解决方案的“build”目录中,在发布中您将拥有可供使用的 freetype.dllfreetype.lib 文件。您将需要这些以及所有freetype-.xxx\include

祝你好运 :)

The future here. This is to future readers of this thread.

FT2 supports creating a static and dynamic library. They have solutions premade and can be found in the builds directory.

If you are forced to use CMAKE, you will have to do what the accepted answer does. However, it is no longer current. I was not able to find said file which references dll (near the "DLL export compilation" remarks section for example):. It is now located at freetype-x.x.x\include\freetype\config\ftconfig.h around line 424. I am using MSVS 2017, so try to follow along.

mkdir build
cd build
cmake -G "Visual Studio 15 2017 Win64" ..

Open freetype-x.x.x\include\freetype\config\ftconfig.h and around line 424, patch the __declspec(dllexport)'s in:

...
  /* You can provide your own implementation of `FT_EXPORT` and        */
  /* `FT_EXPORT_DEF` here if you want.                                 */
  /*                                                                   */
  /* To export a variable, use `FT_EXPORT_VAR`.                        */
  /*                                                                   */

// This is due to FT_EXPORT and FT_BASE not generating a .lib file, just a .dll
#ifdef FT_EXPORT
#undef FT_EXPORT
#define FT_EXPORT(x)  __declspec(dllexport) x
#endif

#ifdef FT_BASE
#undef FT_BASE
#define FT_BASE(x)    __declspec(dllexport) x
#endif

#ifndef FT_EXPORT
...

Open the solution generated by CMAKE called freetype.sln . Select freetype in the Class View. Project -> Properties -> General -> Target Extension -> set to .dll and under Project Defaults -> Configuration Type -> set to Dynamic Library (.dll)

Make sure Release is select and Build -> Build freetype. In the 'build' directory that has the solutions, in Release you will have your freetype.dll and freetype.lib files for use. You will need those and all of freetype-.x.x.x\include.

Good luck :)

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