gpt4 book ai didi

Android NDK,两个静态库和链接

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:00:40 35 4
gpt4 key购买 nike

我一开始将库创建为共享库,但我认为创建一个共享库而其余静态库会更有效率。当它全部共享时,它编译和链接都很好,但是转向静态时,我开始链接“ undefined reference ”。

编辑: 我将所有库构建在一个 Android.mk

Android.mk:

MY_LOCAL_PATH := $(call my-dir)
MY_LOCAL_CFLAGS := -DDEBUG

TARGET_PLATFORM := 'android-4'

LOCAL_PATH := $(MY_LOCAL_PATH)/../../Base

include $(CLEAR_VARS)

LOCAL_MODULE := Base
LOCAL_SRC_FILES := <Base src files>
include $(BUILD_STATIC_LIBRARY)

MY_LOCAL_STATIC_LIBRARIES := Base

MY_LOCAL_C_INCLUDES := $(MY_LOCAL_PATH)/../../Base

LOCAL_PATH := $(MY_LOCAL_PATH)/../../Framework

include $(CLEAR_VARS)

LOCAL_MODULE := Framework
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)
LOCAL_SRC_FILES := <Framework src files>
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)

include $(BUILD_STATIC_LIBRARY)

MY_LOCAL_STATIC_LIBRARIES += Framework

MY_LOCAL_C_INCLUDES += $(MY_LOCAL_PATH)/../../Framework

LOCAL_PATH := $(MY_LOCAL_PATH)/Graphics

include $(CLEAR_VARS)

LOCAL_MODULE := Graphics
LOCAL_SRC_FILES := <Graphics src files>
LOCAL_EXPORT_LDLIBS := -lGLESv1_CM
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)

include $(BUILD_STATIC_LIBRARY)

MY_LOCAL_STATIC_LIBRARIES += Graphics

MY_LOCAL_C_INCLUDES += $(MY_LOCAL_PATH)/Graphics

LOCAL_PATH := $(MY_LOCAL_PATH)/Platform

include $(CLEAR_VARS)

LOCAL_MODULE := Platform
LOCAL_SRC_FILES := <Platform src files>
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)

include $(BUILD_STATIC_LIBRARY)

MY_LOCAL_STATIC_LIBRARIES += Platform

MY_LOCAL_C_INCLUDES += $(MY_LOCAL_PATH)/Platform

LOCAL_PATH := $(MY_LOCAL_PATH)

include $(CLEAR_VARS)

LOCAL_MODULE := Final
LOCAL_SRC_FILES := <Final src files>
LOCAL_STATIC_LIBRARIES := $(MY_LOCAL_STATIC_LIBRARIES)
LOCAL_LDLIBS := -llog
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)

include $(BUILD_SHARED_LIBRARY)

ndk-build V=1 -B 的最后一行:

SharedLibrary  : libFinal.so
/Users/robbie/Library/Frameworks/Android-NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-g++ -Wl,-soname,libFinal.so -shared --sysroot=/Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm <object files> /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libBase.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libFramework.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libGraphics.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libPlatform.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libstdc++.a /Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib/libc.so /Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib/libstdc++.so /Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib/libm.so -Wl,--no-undefined -Wl,-z,noexecstack -L/Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib -llog -lGLESv1_CM -lstdc++ -Wl,-rpath-link=/Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib -lsupc++ -o /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libFinal.so
/Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libPlatform.a(ATexture.o): In function `ATexture':
/Users/robbie/Documents/Apps/Revolution/Android/jni/SpinTap/ATexture.cpp:9: undefined reference to `TextureRenderer::TextureRenderer(unsigned int)'
/Users/robbie/Documents/Apps/Revolution/Android/jni/SpinTap/ATexture.cpp:9: undefined reference to `TextureRenderer::TextureRenderer(unsigned int)'

Edit2:TextureRenderer在Graphics中,包含在内。

有谁知道为什么它可能不起作用以及如何解决它?

最佳答案

对我来说,这看起来像是一个链接顺序问题。

你的命令行是:

arm-linux-androideabi-g++ -Wl,-soname,libFinal.so -shared \
libBase.a libFramework.a libGraphics.a libPlatform.a -o libFinal.so

错误是

libPlatform.a(ATexture.o): In function `ATexture':
ATexture.cpp:9: undefined reference to `TextureRenderer'
ATexture.cpp:9: undefined reference to `TextureRenderer'

TextureRenderer 在 Graphics 中。但是 libGraphics 在命令行上位于 libPlatform 之前。 g++ 将按照给定的顺序在命令行上搜索每个库,加载函数以解析外部引用。它将读取 libGraphics 一次,加载解析外部引用的函数,然后转到 libPlatform。

尝试将 LOCAL_STATIC_LIBRARIES := $(MY_LOCAL_STATIC_LIBRARIES) 更改为 LOCAL_STATIC_LIBRARIES := Platform Graphics Framework Ba​​se 并查看进展情况。

关于Android NDK,两个静态库和链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4765465/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com