Error compiling Android NDK

2»

Comments

  • Hi @juaxix.

    It looks like you are linking against both, stdc++ and c++_static. The former is the gnu stdlib, while the latter is the clang stdlib. I don't know what happens, when one links against multiple standard library implementations, but those 2 are not binary compatible to each other. This may be the reason for those undefined reference errors, as I did not see anything else suspicious (but I may have overlooked something).
  • juaxixjuaxix
    edited September 2016
    I think that's not the problem,...I've just compiled both only with c++_static but got the same compile error for the app project
    [exec] jni/prebuilt/plugins/armeabi-v7a/PhotonCloudAPI.a(Plugin.o):Plugin.c pp:function _GLOBAL__sub_I_Plugin.cpp: error: undefined reference to 'std::ios_b ase::Init::Init()'

    http://libcxx.llvm.org/

    Do you think the plugin Makefile is ok?, i would like to use another method, instead of the objects extract with AR to be included in the .a
  • Hi @juaxix.

    Maybe the cause is a missing
    APP_STL := c++_static
    line in the Application.mk of the plugin?
  • Hi @juaxix.

    Maybe the cause is a missing
    APP_STL := c++_static
    line in the Application.mk of the plugin?

    The plugin does not use Application.mk or Android.mk, it's a Makefile, you can see there the -lc++_static parameter in CPPFLAGS, i tried changing these parameters but it all have the same result...
  • Hi @juaxix.

    Isn't CPPFLAGS for arguments that are passed to the compiler? I think there should be something like LDFLAGS or so for arguments that go to the linker. I think -lc++_static needs to go there.
  • Hello @Kaiserludi , finally, and with help i managed to compile the plugin as a static lib (.a) and use it in a game to build the apk (shared), using the photon libs as .a directly, it was a mix of changes of NDK, flags and makefile configuration.
    Thanks for your time, and i'll post the plugin url for the engine in the forum soon!
  • Hi @juaxix.

    Thanks for the great news.

    mix of changes of NDK, flags and makefile configuration

    It would be great, if you could summarize which changes you had to do to finally get it working, so that anyone else running into the same problem knows what he might need to change in his own project.
  • juaxixjuaxix
    edited September 2016
    Ok, first compile as normal LoadBalancing Project, then, use the common-cpp,photon-cpp and loadbalancing libs (.a) in the static_plugin.a makefile as static prebuilt includes.
    Use the same technique for the game makefile (build as shared), including the plugin.a as static together with the other 3 static photoncloud libs.
    The flags,
    LOCAL_CFLAGS := -DANDROID_NDK -Wno-psabi -std=c++11 -DEG_DEBUGGER -D__STDINT_LIMITS -D_EG_ANDROID_PLATFORM -lphoton-cpp-static_$(COMPILE_MODE)_android_armeabi-v7a -lcommon-cpp-static_$(COMPILE_MODE)_android_armeabi-v7a -lloadbalancing-cpp-static_$(COMPILE_MODE)_android_armeabi-v7a

    and
    LOCAL_STATIC_LIBRARIES := loadbalancing-cpp-static-prebuilt photon-cpp-static-prebuilt common-cpp-static-prebuilt
    LOCAL_LDLIBS += -lGLESv2 -lEGL -ldl -llog -latomic

    are important.
    What worked for me was ndk r12b to build loadbalancing and ndk r11c for plugin and game.
  • Thank you, @juaxix.

    Note that although LoadBalancing-cpp ships with it's source for convenience it also ships with prebuilt binaries built from that exact source, so you only need to rebuilt it yourself, if you are actually modifying the source, which usually isn't necessary.
  • I got this error

    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathListzip file "/data/app/demo.android.loadBalancing-GIL4HGl5AqJzcC3EdKzdFg==/base.apk"],nativeLibraryDirectories=[/data/app/demo.android.loadBalancing-GIL4HGl5AqJzcC3EdKzdFg==/lib/arm64, /system/lib64, /system/vendor/lib64] couldn't find "libdemoLoadBalancing.so"

    It seems the system needs .so file. So I tried to get .so file with "ndk-build" command line.
    Is this right?
  • Thank, Btw I tried with Android.mk file.

    # Generated by VisualGDB

    LOCAL_PATH := $(call my-dir)
    PHOTON_SDK_ROOT := $(LOCAL_PATH)/../../../..

    include $(CLEAR_VARS)

    LOCAL_MODULE := demoLoadBalancing
    #VisualGDBAndroid: AutoUpdateSourcesInNextLine
    LOCAL_SRC_FILES := ../../src/NetworkLogic.cpp AndroidNetworkLogic.cpp main.cpp

    LOCAL_C_INCLUDES := $(PHOTON_SDK_ROOT) ../inc/ ../../shared/inc
    LOCAL_CFLAGS := -Werror-implicit-function-declaration -Wall -DEG_DEBUGGER -D__STDINT_LIMITS -D_EG_ANDROID_PLATFORM
    LOCAL_STATIC_LIBRARIES := loadbalancing-cpp-static-prebuilt photon-cpp-static-prebuilt common-cpp-static-prebuilt
    LOCAL_LDLIBS := -llog

    include $(BUILD_SHARED_LIBRARY)

    $(call import-add-path, $(PHOTON_SDK_ROOT)/LoadBalancing-cpp/lib)

    $(call import-module,loadbalancing-cpp-prebuilt)

    This is Demo_loadbalancing project. I m working on this.

    But the below error occured.

    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathListzip file "/data/app/demo.android.loadBalancing-GIL4HGl5AqJzcC3EdKzdFg==/base.apk"],nativeLibraryDirectories=[/data/app/demo.android.loadBalancing-GIL4HGl5AqJzcC3EdKzdFg==/lib/arm64, /system/lib64, /system/vendor/lib64] couldn't find "libdemoLoadBalancing.so"

    What is the solution?
  • w5lM0ls.png
    Its my system structure.
  • Hi @baymax.

    You should just navigate to /Volumes/Data/temp/photon/Demos/demo_loadBalancing/android and then run ndk-build.cmd there and that's it.
    This should not result in a "couldn't find "libdemoLoadBalancing.so" " error, because the Android.mk file does not look for that file, but rather creates it.
  • baymaxbaymax
    edited July 19
    Thank for your answer @Kaiserludi
    https://gofile.io/d/9KkFcg
    https://gofile.io/d/dgLBwj
    I added video and screen to show what is my issue after following your guide. I did not find there is no good answer in google search.

    [arm64-v8a] SharedLibrary : libdemoLoadBalancing.so
    jni/../../../../LoadBalancing-cpp/lib/loadbalancing-cpp-prebuilt/libloadbalancing-cpp-static_debug_android_arm64-v8a.a(AuthenticationValues.o): In function `__static_initialization_and_destruction_0(int, int)':
    E:\a\Android\LoadBalancing-cpp/D:/android-ndk/build//../sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:74: undefined reference to `std::ios_base::Init::Init()'
    E:\a\Android\LoadBalancing-cpp/D:/android-ndk/build//../sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
    E:\a\Android\LoadBalancing-cpp/D:/android-ndk/build//../sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:74: undefined reference to `std::ios_base::Init::~Init()'


    Regards.
  • Hi @baymax.

    Those errors indicate an incompatibility between the stdlib version that your app links against and the one that the Photon libs link against.

    The SDK provides libs that have been built against the gcc version of the stdlib (libstdc++) and libs that have been built against the clang version of the stdlib (libc++).
    The former ones are used on default and the lattter ones have an additional 'libc++' postfix in their filenames.

    It looks like your app links against the clang version of the stdlib and against those builds of Photon libs that link against the gcc version of the stdlib.

    However your app and all 3rd party libs that your apps link to must agreed on using the same version of the stdlib as those 2 incompatible versions can't be mixed with each other.

    Please see https://forum.photonengine.com/discussion/comment/42718/#Comment_42718 for instructions on how to link against the libc++ variants of the Photon libs.

    Doing so should fix your errors.
Sign In or Register to comment.