简体   繁体   English

如何使用 CMake 将 FreeType 导入我的 Android Studio NDK 项目

[英]How to import FreeType to my Android Studio NDK project using CMake

Hello I am beginner in Android NDK programming and I need some help getting freetype library to work with my project.您好,我是 Android NDK 编程的初学者,我需要一些帮助才能让 freetype 库与我的项目一起使用。 I've been trying for 3 hours straight to somehow import freetype to my Android Studio project.我已经尝试了 3 个小时,以某种方式将 freetype 导入我的 Android Studio 项目。 I searched on the internet and could not find any solution that was working.我在互联网上搜索,找不到任何有效的解决方案。 I downloaded the library and put it in my cpp folder of the project.But I don't know how to include freetype.我下载了该库并将其放在项目的cpp文件夹中。但是我不知道如何包含 freetype。 Any help would be appreaciated!任何帮助将不胜感激!

This is how my CMakeLists.txt look and for the files that I have added it works for them:这就是我的CMakeLists.txt的外观和我添加的文件的样子:

cmake_minimum_required(VERSION 3.10.2)



project("firstnative")


include_directories(stb/stb_lib
        GoldFlow/Core
        GoldFlow/Graphics
        GoldFlow/Math
        GoldFlow/glm
        GoldFlow/glm/gtc
        GoldFlow/entt
        GoldFlow/physics
        GoldFlow/scripts

    GoldFlow/freetype/include
    GoldFlow/freetype/include/freetype/
    GoldFlow/freetype/include/freetype/config
    GoldFlow/freetype/include/freetype/internal
    GoldFlow/freetype/include/freetype/internal/services
        )



add_library( 
             Native
           
             SHARED


        GoldFlow/Math/GoldMath.cpp
        GoldFlow/Graphics/Shader.cpp
        GoldFlow/Graphics/Renderer2D.cpp
        GoldFlow/Graphics/Camera.cpp
        GoldFlow/Graphics/Texture.cpp
        GoldFlow/Graphics/SpriteSheet.cpp
        GoldFlow/Core/Scene.cpp
        GoldFlow/Core/GameObject.cpp
        GoldFlow/Core/Application.cpp
        GoldFlow/Core/Controls.cpp
        GoldFlow/Core/Timer.cpp
        GoldFlow/physics/AABB.cpp
        GoldFlow/physics/Objects.cpp
        GoldFlow/scripts/ControllerScript.cpp
        GoldFlow/scripts/CharacterMovingScript.cpp
        


        native.cpp)


add_library(
    Freetype

    SHARED

    GoldFlow/freetype/src/autofit/autofit.c
    GoldFlow/freetype/src/base/ftbase.c
    GoldFlow/freetype/src/base/ftbbox.c
    GoldFlow/freetype/src/base/ftbdf.c
    GoldFlow/freetype/src/base/ftbitmap.c
    GoldFlow/freetype/src/base/ftcid.c
    GoldFlow/freetype/src/base/ftfstype.c
    GoldFlow/freetype/src/base/ftgasp.c
    GoldFlow/freetype/src/base/ftglyph.c
    GoldFlow/freetype/src/base/ftgxval.c
    GoldFlow/freetype/src/base/ftinit.c
    GoldFlow/freetype/src/base/ftmm.c
    GoldFlow/freetype/src/base/ftotval.c
    GoldFlow/freetype/src/base/ftpatent.c
    GoldFlow/freetype/src/base/ftpfr.c
    GoldFlow/freetype/src/base/ftstroke.c
    GoldFlow/freetype/src/base/ftsynth.c
    GoldFlow/freetype/src/base/fttype1.c
    GoldFlow/freetype/src/base/ftwinfnt.c
    GoldFlow/freetype/src/bdf/bdf.c
    GoldFlow/freetype/src/bzip2/ftbzip2.c
    GoldFlow/freetype/src/cache/ftcache.c
    GoldFlow/freetype/src/cff/cff.c
    GoldFlow/freetype/src/cid/type1cid.c
    GoldFlow/freetype/src/gzip/ftgzip.c
    GoldFlow/freetype/src/lzw/ftlzw.c
    GoldFlow/freetype/src/pcf/pcf.c
    GoldFlow/freetype/src/pfr/pfr.c
    GoldFlow/freetype/src/psaux/psaux.c
    GoldFlow/freetype/src/pshinter/pshinter.c
    GoldFlow/freetype/src/psnames/psnames.c
    GoldFlow/freetype/src/raster/raster.c
    GoldFlow/freetype/src/sfnt/sfnt.c
    GoldFlow/freetype/src/smooth/smooth.c
    GoldFlow/freetype/src/truetype/truetype.c
    GoldFlow/freetype/src/type1/type1.c
    GoldFlow/freetype/src/type42/type42.c
    GoldFlow/freetype/src/winfonts/winfnt.c

) )

find_library( 
              log-lib
              
              log )

find_library(GLES-lib

             GLESv3)



target_link_libraries( 
                       Native
             
                       ${log-lib}
                       ${GLES-lib}
                       ${Freetype}

        )

The error I am getting now is this: C:\Users\infer\AndroidStudioProjects\FirstNative\app\src\main\cpp\GoldFlow\freetype\src\base\ftbdf.c:40:14: error: use of undeclared identifier 'FT_ERR_PREFIXInvalid_Face_Handle';我现在得到的错误是: C:\Users\infer\AndroidStudioProjects\FirstNative\app\src\main\cpp\GoldFlow\freetype\src\base\ftbdf.c:40:14 标识符未声明使用:错误: 'FT_ERR_PREFIXInvalid_Face_Handle'; did you mean 'FT_Err_Invalid_Face_Handle'?你的意思是“FT_Err_Invalid_Face_Handle”吗?

Ok the solution was very simple.好的,解决方案非常简单。 All I did actually was I created directory in cpp folder named freetype and in that dir I've put every freetype file and just added that folder as sub directory in CMake and linked at the end and now eveyrthing works.我实际上所做的只是在名为 freetype 的 cpp 文件夹中创建了目录,并在该目录中放置了每个 freetype 文件,然后将该文件夹作为子目录添加到 CMake 中并在最后链接,现在一切正常。 Here is my CMake:这是我的 CMake:

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.10.2)

# Declares and names the project.

project("firstnative")


include_directories(stb/stb_lib
        GoldFlow/Core
        GoldFlow/Graphics
        GoldFlow/Math
        GoldFlow/glm
        GoldFlow/glm/gtc
        GoldFlow/entt
        GoldFlow/physics
        GoldFlow/scripts
        GoldFlow/text
        )

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
        Native

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).



        GoldFlow/Math/GoldMath.cpp
        GoldFlow/Graphics/Shader.cpp
        GoldFlow/Graphics/Renderer2D.cpp
        GoldFlow/Graphics/Camera.cpp
        GoldFlow/Graphics/Texture.cpp
        GoldFlow/Graphics/SpriteSheet.cpp
        GoldFlow/Core/Scene.cpp
        GoldFlow/Core/GameObject.cpp
        GoldFlow/Core/Application.cpp
        GoldFlow/Core/Controls.cpp
        GoldFlow/Core/Timer.cpp
        GoldFlow/physics/AABB.cpp
        GoldFlow/physics/Objects.cpp
        GoldFlow/scripts/ControllerScript.cpp
        GoldFlow/scripts/CharacterMovingScript.cpp
        GoldFlow/text/TextRenderer.cpp



        native.cpp)





# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
#sd




find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log )

find_library(GLES-lib

        GLESv3)

add_subdirectory(freetype)



target_link_libraries( # Specifies the target library.
        Native

        # Links the target library to the log and gl es library
        # included in the NDK.
        ${log-lib}
        ${GLES-lib}
        freetype
        )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM