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?
3 Answers
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):#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 theobjs\win32\vc2010
directory.

- 36,091
- 7
- 95
- 123

- 132,049
- 21
- 248
- 298
-
those binaries are from 9 March 2008 (version 2.3.5 ...) current Version is 2.4.6... – Titusz Sep 13 '11 at 12:29
-
@Titusz - Good point. I have updated my answer. However, if you're the downvoter, it would be nice to make sure the question is complete so we know the whole story before answering. – Simon Mourier Sep 13 '11 at 13:33
-
this worked perfectly... thank you very much... bounty well earned ;.) – Titusz Sep 15 '11 at 09:40
-
1There should be a third `#define` in `ftoption.h` if you want to export everything: `#define FT_EXPORT_DEF(x) __declspec(dllexport) x`. https://github.com/Robmaister/SharpFont/issues/24 – Robert Rouhani Jul 15 '13 at 20:32
-
Does anyone know how to do the compilation using mingw? – msmechanized May 17 '14 at 16:19
-
I additionally had to change the `Target Extension` in the project config `General` Tab to `.dll`. When installing the Freetype, the .dll is not copied, but you can do it manually. – yanlend Aug 21 '15 at 19:47
-
2Does anyone know why the FreeType `CMakeLists.txt` actively forbids building as shared library with MSVC despite this answer showing how trivial it is to do? – LB-- Oct 31 '15 at 14:15
-
Not sure the notion of "shared lib" in this file is strictly the same as the DLL concept (with binary exports in different files) in Windows, although I agree it sounds logical ? Maybe you could send an email to the guys listed in such readme files. – Simon Mourier Oct 31 '15 at 16:09
-
In Freetype2.9, the `DLL export compilation` section has disapered. Is `ftoption.h` still the good spot? And it causes a problem when building projects with `harfbuzz` which needs certain symbols exported from FT. I'm now thinking to write to both authors. – Sandburg Apr 18 '18 at 15:38
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 :)

- 563
- 1
- 6
- 16
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.

- 1
- 1

- 65,299
- 14
- 133
- 152