将 FreeType 编译为 DLL(与静态库相反)
我想在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您可以使用旧版本(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 thebuilds\win32\vc2010
directory.open the project config, and in the
General
tab, changeConfiguration Type
toDynamic Library (.dll)
open the
ftoption.h
file, and add these lines (near the "DLL export compilation" remarks section for example):change the project compilation configuration to "Release".
compile the project. You should now have a
freetype246.dll
in theobjs\win32\vc2010
directory.我敢打赌,问题在于您的 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.
未来在这里。这是写给该主题的未来读者的。
FT2支持创建静态和动态库。他们有预制的解决方案,可以在
builds
目录中找到。如果您被迫使用 CMAKE,您将必须执行已接受的答案的操作。然而,它不再是当前的。我无法找到引用 dll
的所述文件(例如在“DLL 导出编译”备注部分附近):
。它现在位于第 424 行附近的freetype-xxx\include\freetype\config\ftconfig.h
。我使用的是 MSVS 2017,因此请尝试遵循。打开 freetype-xxx\include\freetype\config\ftconfig.h 并在第 424 行左右,修补
__declspec(dllexport)
的位置:打开 CMAKE 生成的解决方案,名为自由类型.sln。在类视图中选择 freetype。项目->属性->一般->目标扩展 ->设置为
.dll
并在 Project Defaults -> 下配置类型->设置为Dynamic Library (.dll)
确保选择Release 并Build ->构建自由类型。在包含解决方案的“build”目录中,在发布中您将拥有可供使用的
freetype.dll
和freetype.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 atfreetype-x.x.x\include\freetype\config\ftconfig.h
around line 424. I am using MSVS 2017, so try to follow along.Open
freetype-x.x.x\include\freetype\config\ftconfig.h
and around line 424, patch the__declspec(dllexport)
's in: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 toDynamic 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
andfreetype.lib
files for use. You will need those and all offreetype-.x.x.x\include
.Good luck :)