我正在尝试在android studio中使用C ++库Freetype。我可以在使用命令用g ++编译的普通C ++项目中正确使用它
g++ my_code.cpp -I/usr/local/include/freetype2 -L/usr/local/lib -lfreetype
因此很明显,库已正确编译。但是,我在修改android.mk以链接到该库时遇到问题。我能够正确包含头文件(即,-I / usr / local / include / freetype2标志正在工作),但是当我尝试运行功能时,android studio build失败,并显示诸如/home/jonathan/OvrSdk/ovr_sdk_mobile_1.18.0/MyProjects/Triz/Projects/Android/jni/../../../Src/TriangleGameMenu.cpp:84: undefined reference to 'FT_Init_FreeType'
之类的错误消息。完整的错误消息:
Build command failed.
Error while executing process /home/jonathan/Android/Sdk4/ndk-bundle/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/jonathan/OvrSdk/ovr_sdk_mobile_1.18.0/MyProjects/Triz/Projects/Android/jni/Android.mk NDK_APPLICATION_MK=/home/jonathan/OvrSdk/ovr_sdk_mobile_1.18.0/MyProjects/Triz/Projects/Android/jni/Application.mk APP_ABI=arm64-v8a NDK_ALL_ABIS=arm64-v8a NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=/home/jonathan/OvrSdk/ovr_sdk_mobile_1.18.0/MyProjects/Triz/Projects/Android/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/home/jonathan/OvrSdk/ovr_sdk_mobile_1.18.0/MyProjects/Triz/Projects/Android/build/intermediates/ndkBuild/debug/lib V=0 -j4 -C/home/jonathan/OvrSdk/ovr_sdk_mobile_1.18.0/MyProjects/Triz/Projects/Android APP_PLATFORM=android-21 NDK_TOOLCHAIN_VERSION=clang APP_STL=c++_static NDK_DEBUG=1 OVR_DEBUG=1 /home/jonathan/OvrSdk/ovr_sdk_mobile_1.18.0/MyProjects/Triz/Projects/Android/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/libtriz.so}
make: Entering directory `/home/jonathan/OvrSdk/ovr_sdk_mobile_1.18.0/MyProjects/Triz/Projects/Android'
[arm64-v8a] SharedLibrary : libtriz.so
/home/jonathan/OvrSdk/ovr_sdk_mobile_1.18.0/MyProjects/Triz/Projects/Android/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/triz/__/__/__/Src/TriangleGameMenu.o: In function `TriangleGameMenu':
/home/jonathan/OvrSdk/ovr_sdk_mobile_1.18.0/MyProjects/Triz/Projects/Android/jni/../../../Src/TriangleGameMenu.cpp:84: undefined reference to `FT_Init_FreeType'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/home/jonathan/OvrSdk/ovr_sdk_mobile_1.18.0/MyProjects/Triz/Projects/Android/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/libtriz.so] Error 1
make: Leaving directory `/home/jonathan/OvrSdk/ovr_sdk_mobile_1.18.0/MyProjects/Triz/Projects/Android'
我的android.mk文件如下:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := triz
LOCAL_CPPFLAGS := -Wno-narrowing -I/usr/local/include/freetype2 -L/usr/local/lib -lfreetype
LOCAL_SRC_FILES := (bunch of source files)
LOCAL_LDLIBS := -llog -landroid -lGLESv3 -lEGL # include default libraries
LOCAL_LDFLAGS := -u ANativeActivity_onCreate
LOCAL_STATIC_LIBRARIES := android_native_app_glue
LOCAL_SHARED_LIBRARIES := vrapi
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
$(call import-module,VrApi/Projects/AndroidPrebuilt/jni)
我的问题确实是我不知道应该在android.mk文件(或其他文件)中放置不同的标志。所以现在我将所有要传递给g ++的标志放在LOCAL_CPPFLAGS中,但这显然不起作用。将-lfreetype移到LOCAL_LDLIBS也不起作用。