Issue
I'm trying to build a valid Android library to be used with a game engine called ShiVa, here it is the problem too: engine forum, photon cloud forum, but I think I've reached the point to ask in stackoverflow, because the main error now is this:
[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()'
I found this error in here, but I'm not using any string.h, only string and similar libs, well, this is the Shiva plugin Makefile:
#################################################################
# 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)
####################################################################"
That produces me the game engine libraries (.a) for android app projects. Ah, you can see the Makefile uses obj/*.o files, these are extracted from the compiled photon libraries (.a) using the AR -x because the rcs method is not compatible, as the libs are not elf.
This is the Game Project Android.mk, that uses PhotonCloudAPI_Android*.a files generated by the previous makefile build process (yeah, it compiles).
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)
Game Project 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
I have tried everything, I think the Shiva plugin Makefile is wrong, maybe I need to add the std libs in the linking too? it compiles, but then it's the game that uses the compiled .a the one that fails to compile.
Solution
I found the error, the objects extracted from the static libs contains references to the missing c++ libraries. I used the static libs directly as .a and compile the first plugin.a as static and then I used this, linking the same libs again with the new plugin.a as static for a dynamic library for the game.
Answered By - juaxix
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.