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

如何使用CMake将FreeType导入我的Android Studio NDK项目,android,android-studio,cmake,android-ndk,Android,Android Studio,Cmake,Android Ndk,你好,我是Android NDK编程的初学者,我需要一些帮助,让freetype库与我的项目一起工作。我已经连续3个小时试图以某种方式将freetype导入到我的Android Studio项目中。我在互联网上搜索,找不到任何有效的解决方案。我下载了这个库,并把它放在项目的cpp文件夹中。但是我不知道如何包含freetype。任何帮助都会得到报答 以下是myCMakeLists.txt的外观以及我添加的文件的工作方式: cmake_minimum_required(VERSION 3.10.2)

你好,我是Android NDK编程的初学者,我需要一些帮助,让freetype库与我的项目一起工作。我已经连续3个小时试图以某种方式将freetype导入到我的Android Studio项目中。我在互联网上搜索,找不到任何有效的解决方案。我下载了这个库,并把它放在项目的cpp文件夹中。但是我不知道如何包含freetype。任何帮助都会得到报答

以下是myCMakeLists.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
)


我现在遇到的错误是:C:\Users\expert\AndroidStudioProjects\FirstNative\app\src\main\cpp\GoldFlow\freetype\src\base\ftbdf.C:40:14:错误:使用未声明的标识符“FT\u ERR\u PREFIXInvalid\u Face\u Handle”;你是说“FT\u Err\u Invalid\u Face\u Handle”吗?

好的,解决方案非常简单。实际上,我所做的只是在名为freetype的cpp文件夹中创建了一个目录,在这个目录中,我放置了每个freetype文件,并将该文件夹作为子目录添加到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
        )

欢迎您从中获取Android的freetype(包括构建脚本)。这在Windows上不起作用,但你可以在你的Windows上安装Ubuntu(又称WSL)。@AlexCohn谢谢你的回复Alex。有没有其他不必安装ubuntu的方法?WSL的安装很简单,它比cygwin黑客的旧方法更干净。您可以在任何Linux机器或Mac上构建freetype。请注意,您只能执行一次:您的项目将使用生成的二进制文件和生成的标题。您可以尝试通过其官方
CMakeLists.txt
在Windows上构建freetype,我再次建议您将其作为Android项目中的一个单独模块来执行。如果你精通CMake,你可以设置为freetype。谢谢,我现在就做。
# 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
        )