前面讲诉了在windows下面freetype的编译,本文介绍freetype 在Linux下面的编译。
一、准备工作:
下载freetype,地址:http://www.freetype.org/download.html,本文所用版本:2.5.3
下载zlib,地址:http://www.zlib.net/,本文所用版本:1.2.8
二、编译freetype
1.解压包freetype-2.5.3.tar
2.cd freetype-2.5.3
3. ./configure --prefix=/home/lin/freetype
注意:在make的时候若是出现如下错误:
configure: creating ./config.status
config.status: creating unix-cc.mk
config.status: creating unix-def.mk
config.status: creating freetype-config
config.status: creating freetype2.pc
config.status: creating ftconfig.h
FreeType build system -- automatic system detection
The following settings are used:
platform unix
compiler cc
configuration directory ./builds/unix
configuration rules ./builds/unix/unix.mk
If this does not correspond to your system or settings please remove the file
`config.mk' from this directory then read the INSTALL file for help.
Otherwise, simply type `make' again to build the library,
or `make refdoc' to build the API reference (the latter needs python).
make: Nothing to be done for `unix'.
这时,进入UNIX中编译, cd /builds/unix
./configure
cd ../../
4. make
5. sudo make install
然后,在/home/lin/freetype下的include和lib分别为头文件目录及库目录(包括静态库及动态库)
静态库:libfreetype.a
动态库:libfreetype.so
三、编译zlib1.解压zlib-1.2.8.tar
2. cd zlib-1.2.8
3. ./configure –prefix=/home/lin/zlib
4. make
5. sudo make install
在/home/lin/zlib下的include和lib分别为头文件目录及库目录(包括静态库及动态库)
静态库:libz.a
动态库:libz.so
四、使用
静态库链接时,使用如下链接标志:
LINK_DIRECTORIES( "${Test_SOURCE_DIR}/lib/" ) //lib是存放静态库的文件夹
TARGET_LINK_LIBRARIES(
Test " libfreetype.a" "libz.a")
INCLUDE_DIRECTORIES( "${Test_SOURCE_DIR}/header") //header中是存放的有关静态库的头文件
动态库链接标志:
把动态库:libfreetype.so libz.so这两个动态库放到当前目录下的lib文件夹中(路径比如:/home/stduy/test/lib)
在/etc/profile中加入环境设置:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/stduy/test/lib
编译程序,搞定。