开发者

Compiling FreeType to DLL (as opposed to static library)

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?


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.


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.


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜