Compilation of FreeType2 under win32

Source: Internet
Author: User
In fact, I already have a lot of knowledge on the Internet. The purpose of this article is to deepen my impression and accumulate experience. Someone told me that writing an article is also a good help for myself. I hope this article will be helpful to other people. For details, please refer to the unclear and incorrect descriptions due to poor writing skills. I don't know much about FreeType2L.

In fact, I already have a lot of knowledge on the Internet. The purpose of this article is to deepen my impression and accumulate experience. Someone told me that writing an article is also a good help for myself. I hope this article will be helpful to other people. For details, please refer to the unclear and incorrect descriptions due to poor writing skills. I don't know much about FreeType2L.


In fact, I already have a lot of knowledge on the Internet. The purpose of this article is to deepen my impression and accumulate experience. Someone told me that writing an article is also a good help for myself. I hope this article will be helpful to other people. For details, please refer to the unclear and incorrect descriptions due to poor writing skills.
I will not talk much about FreeType2L. There are still many articles on the Internet. In addition, this article only describes my installation experience and does not introduce the use of FreeType2. If necessary, read the reference manual.

Opening part:

Download source code from http://www.freetype.org.

The source code package of FreeType2 contains make files in multiple environments and compilers. It also contains vc project files.

I use VC, So I first find the project file of the VC environment. This file is under the/builder/win32/visualc Directory, which contains the project files of vc6 and vs2005. However, it seems that the project file of its vc6 version is a bit problematic. I cannot open it correctly with vc6, but vs2005 can work well. Open the vs2005 project and compile it. If there is no error, the corresponding lib static library file will be generated under the/objs directory. The above process is a common method.

However, one problem is that the official project files can only generate static link library files (LIB). If you want to generate dynamic link library (DLL) files, then you have to find a solution. My focus is on how to compile a DLL file.
My working environment is VC6, but because the official vc6 file is faulty, I am too lazy to see what the problem is, so I prefer to recreate my project file.

Solution:
Freetype2 is a highly customizable library, and the documentation in the FreeType2 package is enough for me to do what I want.
Step 1:
The first document I reference is INSTALL. ANY IN THE/doc directory. This document has clearly explained the files to be included in the standard compilation and their functions. What I want to do now is to create a vc6 win32DLL project and select the empty project option, generate an empty dll project, and then follow INSTALL. ANY to add the file to the project, INSTALL. there is an obvious reminder in the ANY file: "do not compile all c files! ", Do not compile all C files.
Step 2:
The second file to be referenced and modified is ftoption. h. The file is in the/include/freetype/config Directory, which stores some configuration header files. The ftoption. h file provides detailed explanations for each customizable project, and provides three methods for configuring FreeType2 library using ftoption. h. The method I used does not know whether it is one of them:
1. First back up ftoption. h, for example, save it as the ftoption_bak.h file.
Ii. According to ftoption. h description in the "DLL export compilation" item. The FreeType2 library uses FT_EXPORT (used in Function Definition) and FT_EXPORT_DEF (used in function declaration) Two macros before the function to be exported, so I just need to redefine the two macros and then OK. The FreeType2 library defines FT_EXPORT and FT_EXPORT_DEF macros in the ftconfig. h file by default.

My approach is to redefine FT_EXPORT and FT_EXPORT_DEF at ftopion. h, as shown below:

# Ifdef FT2_DLL // because this file is used in both the static library and the dynamic library, this indicator is used differently. FT2_DLL indicates that the file must be compiled as a DLL dynamic library.
# Ifdef FT2_EXPORTS // DEFINE _ declspec (dllexport) and _ declspec (dllimport) According to Microsoft's standard practices)
# Define FT_EXPORT (x) _ declspec (dllexport) x
# Define FT_EXPORT_DEF (x) x
# Else // according to Microsoft, other _ declspec (dllimport) can also be avoided, but this is more efficient and, if not, sometimes a problem occurs when exporting variables. so! Do as he says.
# Define FT_EXPORT (x) _ declspec (dllimport) x
# Define FT_EXPORT_DEF (x) x
# Endif
# Endif

The DLL compilation must be completed. Note that, because it is a re-built project file, refer to the official project file in ftoption. modify the "Debug level" item in h as follows:

# Ifdef _ DEBUG
# Define FT_DEBUG_LEVEL_ERROR
# Define FT_DEBUG_LEVEL_TRACE
# Endif

3. In the vc6 project file, you need to define FT_DLL (defined earlier), FT_EXPORT (defined earlier), and FT2_BUILD_LIBRARY (required for compiling to a library file) predefined flag. Then define the output directory according to the conventional DLL method. Other pre-compiled commands can generate the DLL file. Note: The. LIB and. EXP files will also be generated.
4. We can also create an empty win32 static Link Library Project in the same way, but the predefined flag is related to Freetype2 and only needs FT2_BUILD_LIBRARY (required to compile it into a library file) predefined flag.

5. Create an empty project file that contains the two project files. The last step is OK.

FreeType2 is a flexible, customizable library with good performance. For more customization, such as module selection and system interface customization, refer to its installation documentation, it is described in this document.

Another 1: You can mention the FTGL library. This is a library that uses FreeType to draw fonts under OpenGL, because the author did not consider (or solve) The FreeType dynamic library problem, therefore, it only contains the project files that use the FreeType2 static library. Friends who use the FTGL library can also modify the files according to the following ideas and recreate their own project files.

Another 2: Three thread libraries used by vc DLL: the six configurations of the vc project file of the original official FreeType2 correspond to the three thread libraries of the release and DEBUG Versions respectively. Single thread: Refers to LIBC. lib is statically linked to the library, multithreading: refers to the LIBCMT. lib static link to the library, multi-threaded DLL: refers to the MSVCRT. dll is dynamically linked to this library. Therefore, the corresponding thread library must be used for projects that use this database.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.