将非elf库链接到单个库时出错

时间:2016-09-03 10:46:34

标签: android c++ makefile android-ndk

我正在尝试构建一个有效的Android库,以便与名为ShiVa的游戏引擎一起使用,这也是问题所在:engine forumphoton cloud forum,但我想我是&#39已经达到了在stackoverflow中询问的要点,因为现在的主要错误是:

 [exec] jni/prebuilt/plugins/armeabi-v7a/PhotonCloudAPI.a(Plugin.o):Plugin.cpp:function _GLOBAL__sub_I_Plugin.cpp: error: undefined reference to 'std::ios_base::Init::Init()'

我在here中发现了这个错误,但是我没有使用任何string.h,只使用字符串和类似的库,好吧,这是 Shiva插件Makefile :< / p>

#################################################################
#   ShiVa Extension Plugin Makefile for Android
#################################################################

ANDROID_NDK_ROOT    = C:/Games/sdks/android-ndk-r12b
TEMP_DIR            = ../../Temp/Android
TEMP_DIR_ARM5       = $(TEMP_DIR)/arm5
TEMP_DIR_ARM7       = $(TEMP_DIR)/arm7
TEMP_DIR_X86        = $(TEMP_DIR)/x86
SRCROOT             = ../../Sources
S3DXROOT            = ../../Sources/S3DX
BUILT_PRODUCTS_DIR  = ../../Contents/Android
PHOTON_DIR          = ../../Libs/Photon-AndroidNDK-Sdk_v4-1-3-3
PRODUCT_NAME_ARM5   = PhotonCloudAPI_Android.a
PRODUCT_NAME_ARM7   = PhotonCloudAPI_Android_arm_v7a.a
PRODUCT_NAME_X86    = PhotonCloudAPI_Android_x86_32.a

#################################################################
#  User data
#
USER_INCLUDE_PATH   = -L"$(PHOTON_DIR)/Common-cpp/lib/common-cpp-prebuilt" -L"$(PHOTON_DIR)/Photon-cpp/lib/photon-cpp-prebuilt" -L"$(PHOTON_DIR)/LoadBalancing-cpp/lib/loadbalancing-cpp-prebuilt"
USER_LIBRARIES_ARM5 = -lphoton-cpp-static_debug_android_armeabi -lcommon-cpp-static_debug_android_armeabi -lloadbalancing-cpp-static_debug_android_armeabi
USER_LIBRARIES_ARM7 = -lphoton-cpp-static_debug_android_armeabi-v7a -lcommon-cpp-static_debug_android_armeabi-v7a -lloadbalancing-cpp-static_debug_android_armeabi-v7a
USER_LIBRARIES_ARX86= -lphoton-cpp-static_debug_android_x86 -lcommon-cpp-static_debug_android_x86 -lloadbalancing-cpp-static_debug_android_armeabi_x86
USER_FLAGS          = 

#################################################################
SOURCES             = Plugin.cpp PhotonCloudAPI.cpp NetworkLogic.cpp Console.cpp

#################################################################
#  Compiler executables
#
CC_ARM5             = "$(ANDROID_NDK_ROOT)/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc" 
CPP_ARM5            = "$(ANDROID_NDK_ROOT)/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++"
AR_ARM5             = "$(ANDROID_NDK_ROOT)/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-ar"

CC_ARM7             = $(CC_ARM5)
CPP_ARM7            = $(CPP_ARM5)
AR_ARM7             = $(AR_ARM5)

CC_X86              = "$(ANDROID_NDK_ROOT)/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/i686-linux-android-gcc"
CPP_X86             = "$(ANDROID_NDK_ROOT)/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/i686-linux-android-g++"
AR_X86              = "$(ANDROID_NDK_ROOT)/toolchains/x86-4.9/prebuilt/windows-x86_64/bin/i686-linux-android-ar"

####################################################################"
#  Includes
#
SYSROOT_ARM5        = $(ANDROID_NDK_ROOT)/platforms/android-9/arch-arm
SYSROOT_ARM7        = $(ANDROID_NDK_ROOT)/platforms/android-16/arch-arm
SYSROOT_X86         = $(ANDROID_NDK_ROOT)/platforms/android-19/arch-x86
SYSTEM_INCLUDES     = -I"$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.9/include"
PHOTON_INCLUDES     = -I"../../Libs/Photon-AndroidNDK-Sdk_v4-1-3-3/" 

####################################################################"
#  Compiler flags
#
CFLAGS_Arch_ARM5    = -march=armv5te -msoft-float -I"$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include"
CFLAGS_Arch_ARM7    = -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -I"$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include"
CFLAGS_Arch_X86     = -I"$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include"
CFLAGS_Common       = -Os -Wno-unknown-pragmas -fPIC -fsigned-char -fno-strict-aliasing -fno-short-enums -fno-exceptions -D__ANDROID__ -DANDROID_NDK -DANDROID -DRELEASE -D_GNU_SOURCE -DHAVE_STDINT_H
CFLAGS_ARM5         = --sysroot="$(SYSROOT_ARM5)" $(CFLAGS_Arch_ARM5) $(CFLAGS_Common) $(SYSTEM_INCLUDES) -I"$(SRCROOT)" -I$(SRCROOT)/Android -I$(S3DXROOT) -I"$(SYSROOT_ARM5)/usr/bin" $(PHOTON_INCLUDES) $(USER_INCLUDE_PATH) $(USER_LIBRARIES_ARM5)
CFLAGS_ARM7         = --sysroot="$(SYSROOT_ARM7)" $(CFLAGS_Arch_ARM7) $(CFLAGS_Common) $(SYSTEM_INCLUDES) -I"$(SRCROOT)" -I$(SRCROOT)/Android -I$(S3DXROOT) -I"$(SYSROOT_ARM7)/usr/bin" $(PHOTON_INCLUDES) $(USER_INCLUDE_PATH) $(USER_LIBRARIES_ARM7)
CFLAGS_X86          = --sysroot="$(SYSROOT_X86)"  $(CFLAGS_Arch_X86)  $(CFLAGS_Common) $(SYSTEM_INCLUDES) -I"$(SRCROOT)" -I$(SRCROOT)/Android -I$(S3DXROOT) -I"$(SYSROOT_X86)/usr/bin" $(PHOTON_INCLUDES) $(USER_INCLUDE_PATH) $(USER_LIBRARIES_ARX86)
CPPFLAGS            = -fno-rtti -lc++_static -lsupc++ -lhosted -lxsde -std=c++11 -lstdc++ 


####################################################################"
#  Objects
#
OBJECTS             = \
    $(patsubst %.c,%.o,$(filter %.c,$(SOURCES))) \
    $(patsubst %.cc,%.o,$(filter %.cc,$(SOURCES))) \
    $(patsubst %.cpp,%.o,$(filter %.cpp,$(SOURCES)))

OBJECTS_ABS_ARM5    = $(addprefix $(TEMP_DIR_ARM5)/,$(OBJECTS))
OBJECTS_ABS_ARM7    = $(addprefix $(TEMP_DIR_ARM7)/,$(OBJECTS))
OBJECTS_ABS_X86     = $(addprefix $(TEMP_DIR_X86)/,$(OBJECTS))
PRODUCT_ABS_ARM5    = $(BUILT_PRODUCTS_DIR)/$(PRODUCT_NAME_ARM5)
PRODUCT_ABS_ARM7    = $(BUILT_PRODUCTS_DIR)/$(PRODUCT_NAME_ARM7)
PRODUCT_ABS_X86     = $(BUILT_PRODUCTS_DIR)/$(PRODUCT_NAME_X86)

####################################################################"
#  Rules
#

$(TEMP_DIR_ARM5)/%.o: $(SRCROOT)/%.c
    @mkdir -p `dirname $@`
    @echo Compiling $<
    @$(CC_ARM5) $(CFLAGS_ARM5) -c $< -o $@

$(TEMP_DIR_ARM5)/%.o: $(SRCROOT)/%.cpp
    @mkdir -p `dirname $@`
    @echo Compiling $<
    @$(CPP_ARM5) $(CFLAGS_ARM5) $(CPPFLAGS) -c $< -o $@

$(TEMP_DIR_ARM7)/%.o: $(SRCROOT)/%.c
    @mkdir -p `dirname $@`
    @echo Compiling $<
    $(CC_ARM7) $(CFLAGS_ARM7) -c $< -o $@

$(TEMP_DIR_ARM7)/%.o: $(SRCROOT)/%.cpp
    @mkdir -p `dirname $@`
    @echo Compiling $<
    $(CPP_ARM7) $(CFLAGS_ARM7) $(CPPFLAGS) -c $< -o $@

$(TEMP_DIR_X86)/%.o: $(SRCROOT)/%.c
    @mkdir -p `dirname $@`
    @echo Compiling $<
    @$(CC_X86) $(CFLAGS_X86) -c $< -o $@

$(TEMP_DIR_X86)/%.o: $(SRCROOT)/%.cpp
    @mkdir -p `dirname $@`
    @echo Compiling $<
    @$(CPP_X86) $(CFLAGS_X86) $(CPPFLAGS) -c $< -o $@

####################################################################"
#  Targets
#
all: $(PRODUCT_ABS_ARM5) $(PRODUCT_ABS_ARM7) $(PRODUCT_ABS_X86) 

$(PRODUCT_ABS_ARM5): $(OBJECTS_ABS_ARM5)
    @echo Creating ARM5 archive
    @mkdir -p $(BUILT_PRODUCTS_DIR)
    @$(AR_ARM5) rcs $(PRODUCT_ABS_ARM5) $(OBJECTS_ABS_ARM5)  
#./obj/*.o

$(PRODUCT_ABS_ARM7): $(OBJECTS_ABS_ARM7)
    @echo Creating ARM7 archive
    @mkdir -p $(BUILT_PRODUCTS_DIR)
    $(AR_ARM7) rcs $(PRODUCT_ABS_ARM7) $(OBJECTS_ABS_ARM7) ./obj/*.o

$(PRODUCT_ABS_X86): $(OBJECTS_ABS_X86)
    @echo Creating X86 archive
    @mkdir -p $(BUILT_PRODUCTS_DIR)
    @$(AR_X86) rcs $(PRODUCT_ABS_X86) $(OBJECTS_ABS_X86) 
#./obj/*.o

clean:
    @echo Cleaning
    @rm -f $(PRODUCT_ABS_ARM5) $(OBJECTS_ABS_ARM5) $(PRODUCT_ABS_ARM7) $(OBJECTS_ABS_ARM7) $(PRODUCT_ABS_X86) $(OBJECTS_ABS_X86)

####################################################################"

这为我的Android应用程序项目生成了游戏引擎库(.a)。 啊,你可以看到Makefile使用obj / * .o文件,这些是使用AR -x从编译的光子库(.a)中提取的,因为rcs method不兼容,因为lib不是小精灵。

这是 Game Project Android.mk ,它使用由前一个makefile构建过程生成的PhotonCloudAPI_Android * .a文件(是的,它编译)。

LOCAL_PATH             := $(call my-dir)
ANDROID_NDK_ROOT       := C:/Games/sdks/android-ndk-r12b

include $(CLEAR_VARS)
INC_PATH := $(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.9/include/
LOCAL_C_INCLUDES += $(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.9/include/

include $(CLEAR_VARS)
LOCAL_MODULE           := S3DClient_Android
LOCAL_SRC_FILES        := prebuilt/engine/$(TARGET_ARCH_ABI)/libS3DClient_Android.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE           := openal
LOCAL_SRC_FILES        := prebuilt/thirdparty/$(TARGET_ARCH_ABI)/libopenal.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE           := ssl
LOCAL_SRC_FILES        := prebuilt/thirdparty/$(TARGET_ARCH_ABI)/libssl.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE           := crypto
LOCAL_SRC_FILES        := prebuilt/thirdparty/$(TARGET_ARCH_ABI)/libcrypto.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE           := PhotonCloudAPI
LOCAL_SRC_FILES        := prebuilt/plugins/$(TARGET_ARCH_ABI)/PhotonCloudAPI.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
NDK_DEBUG_IMPORTS      := 1
NDK_DEBUG_MODULES      := 1
LOCAL_CFLAGS           :=  -DANDROID_NDK -Wno-psabi -fno-rtti  -lc++_static -lsupc++ -DEG_DEBUGGER -D__STDINT_LIMITS -D_EG_ANDROID_PLATFORM 
LOCAL_ARM_MODE         := arm
LOCAL_MODULE           := S3DClient
LOCAL_MODULE_FILENAME  := libS3DClient
LOCAL_SRC_FILES        := S3DClient.cpp
LOCAL_STATIC_LIBRARIES := S3DClient_Android
LOCAL_SHARED_LIBRARIES := openal ssl crypto
LOCAL_WHOLE_STATIC_LIBRARIES += PhotonCloudAPI photon-cpp-static-prebuilt libcommon-cpp-static-prebuilt loadbalancing-cpp-static    
LOCAL_LDLIBS += -lGLESv2 -lEGL -ldl -llog -latomic -I"$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include"
include $(BUILD_SHARED_LIBRARY)

游戏项目Application.mk

APP_OPTIM        := debug
APP_CFLAGS       += -O3
APP_ABI          := armeabi-v7a
APP_PLATFORM     := android-14
APP_MODULES      := S3DClient
APP_PROJECT_PATH := 
APP_STL          := c++_static

我已经尝试了一切,我认为Shiva插件Makefile是错误的,也许我需要在链接中添加std libs?它编译,但然后它是使用编译的.a的游戏,无法编译。

1 个答案:

答案 0 :(得分:0)

我发现错误,从静态库中提取的对象包含对缺少的c ++库的引用。 我直接使用静态库作为.a并将第一个plugin.a编译为静态然后我使用它,将新的plugin.a再次链接到相同的库,作为游戏动态库的静态。