QT编译 Freetype 2.6.1 windows ubuntu

1、下载源码

https://download.savannah.gnu.org/releases/freetype/

2、新建QT Lib 工程

QT编译 Freetype 2.6.1 windows ubuntu_第1张图片

我的工程名:freetype2-6-1
然后删除除.pro文件之外的文件

下面内容覆盖到.pro文件中

QT      -= core gui
TARGET = freetype
TEMPLATE = lib
CONFIG(debug, debug|release) {
    mac: TARGET = $$join(TARGET,,,_debug)
    win32: TARGET = $$join(TARGET,,,d)
}
DEFINES += FREETYPE261_LIBRARY
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += FT2_BUILD_LIBRARY
DEFINES += WIN32
DEFINES += _LIB
DEFINES += _CRT_SECURE_NO_WARNINGS
DEFINES += FT_DEBUG_LEVEL_ERROR
DEFINES += FT_DEBUG_LEVEL_TRACE
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
    $$PWD/src/autofit/afangles.c \
    $$PWD/src/autofit/afdummy.c \
    $$PWD/src/autofit/afglobal.c \
    $$PWD/src/autofit/afhints.c \
    $$PWD/src/autofit/aflatin.c \
    $$PWD/src/autofit/afloader.c \
    $$PWD/src/autofit/afmodule.c \
    $$PWD/src/autofit/autofit.c \
    $$PWD/src/base/ftbase.c \
    $$PWD/src/base/ftbitmap.c \
    $$PWD/src/base/ftbbox.c \
    $$PWD/src/base/ftdebug.c \
    $$PWD/src/base/ftglyph.c \
    $$PWD/src/base/ftinit.c \
    $$PWD/src/base/ftlcdfil.c \
    $$PWD/src/base/ftmm.c \
    $$PWD/src/base/ftsynth.c \
    $$PWD/src/base/fttype1.c \
    $$PWD/src/bdf/bdf.c \
    $$PWD/src/cache/ftcache.c \
    $$PWD/src/cff/cff.c \
    $$PWD/src/cid/type1cid.c \
    $$PWD/src/gzip/ftgzip.c \
    $$PWD/src/lzw/ftlzw.c \
    $$PWD/src/otvalid/otvalid.c \
    $$PWD/src/otvalid/otvbase.c \
    $$PWD/src/otvalid/otvcommn.c \
    $$PWD/src/otvalid/otvgdef.c \
    $$PWD/src/otvalid/otvgpos.c \
    $$PWD/src/otvalid/otvgsub.c \
    $$PWD/src/otvalid/otvjstf.c \
    $$PWD/src/otvalid/otvmod.c \
    $$PWD/src/pcf/pcf.c \
    $$PWD/src/pfr/pfr.c \
    $$PWD/src/psaux/psaux.c \
    $$PWD/src/pshinter/pshinter.c \
    $$PWD/src/psnames/psmodule.c \
    $$PWD/src/raster/raster.c \
    $$PWD/src/sfnt/sfnt.c \
    $$PWD/src/smooth/smooth.c \
    $$PWD/src/truetype/truetype.c \
    $$PWD/src/type1/type1.c \
    $$PWD/src/type42/type42.c \
    $$PWD/src/winfonts/winfnt.c
INCLUDEPATH += $$PWD/include
win32 {
    SOURCES += $$PWD/src/base/ftsystem.c
} else {
    SOURCES += $$PWD/builds/unix/ftsystem.c
    INCLUDEPATH += $$PWD/builds/unix
}
HEADERS +=

复制源码如下目录到新建的工程下


QT编译 Freetype 2.6.1 windows ubuntu_第2张图片
image.png

在QTCteater中显示如下


QT编译 Freetype 2.6.1 windows ubuntu_第3张图片
工程一览图

此时在windows下构建会得到


QT编译 Freetype 2.6.1 windows ubuntu_第4张图片
debug模式

QT编译 Freetype 2.6.1 windows ubuntu_第5张图片
release模式

在Ubuntu(linux)下构建会找不到 ftconfig.h

:-1: error: No rule to make target '../builds/unix/ftconfig.h', needed by 'ftsystem.o'.  Stop.

这时候需要把 builds/uninx/ftconfig.in 复制一份并重命名 ftconfig.h


QT编译 Freetype 2.6.1 windows ubuntu_第6张图片
复制fitconfig.in并重命名为fitconfig.h

重新尝试构建错误如下:


QT编译 Freetype 2.6.1 windows ubuntu_第7张图片
/home/q/qtproj/freetype2-6-1/builds/unix/ftsystem.c:241: error: 'O_RDONLY' undeclared (first use in this function)
     file = open( filepathname, O_RDONLY );
                                ^

此时需要在builds/unix/ftsystem.c 中 include fcntl.h


QT编译 Freetype 2.6.1 windows ubuntu_第8张图片
image.png

重新构建会生成.so文件,如下图


QT编译 Freetype 2.6.1 windows ubuntu_第9张图片
构建效果图

环境如下
QT编译 Freetype 2.6.1 windows ubuntu_第10张图片
构建套件

QT编译 Freetype 2.6.1 windows ubuntu_第11张图片
构建设置

QT编译 Freetype 2.6.1 windows ubuntu_第12张图片
image.png

工程下载:https://download.csdn.net/download/vbaohui/11603588

后面补充如何使用

你可能感兴趣的:(QT编译 Freetype 2.6.1 windows ubuntu)