Domanda

After more than two days of building errors, I give up...

I followed this good tutorial here: http://www.cryptopp.com/wiki/Android_(Command_Line) . It compiles, and the "cryptest.exe" passes all tests. So, I guess that the static library "libcryptopp.a" is OK.

So, I move the "libcryptopp.a" and all the headers files in the Android project.

But when it comes to the building step (as often... :-) ), there are compilation errors, like:

    .../Classes/libs/android/libcryptopp.a(files.o): in function std::basic_filebuf<char, std::char_traits<char> >::_M_unshift() 
    [clone .part.40]:/Users/toto/Developer/NDKs/AndroidNDKs/android-ndk-r8e/sources/cxx-stl/stlport/stlport/stl/_fstream.h:322: 
    error: undefined reference to 'std::_Filebuf_base::_M_write(char*, int)' 

    and ~50 others ... 

"undefined reference to" errors usually mean that a library is not present, but "libcryptopp.a" is correct here. So I expect that something is missing in the "Android.mk":

    include $(CLEAR_VARS) 
    LOCAL_MODULE    := cryptopp-prebuilt 
    LOCAL_SRC_FILES := ...narf/Classes/libs/android/libcryptopp. 
    include $(PREBUILT_STATIC_LIBRARY) 


    include $(CLEAR_VARS) 
    /* 
       here are included other library 
    */ 

    LOCAL_STATIC_LIBRARIES := cryptopp-prebuilt                 
    include $(BUILD_SHARED_LIBRARY) 

After tries with "APP_STL := stlport_static/dynamic", "APP_STL := gnustl_static/dynamic", etc... no more chances.

Being really not a building/compilation expert (even worse on Android), can somebody help me. Thank you very much!

È stato utile?

Soluzione

Ok. It is working now!

So the linking of "libcryptopp.a" is not working on my Android project with "stlport" but only with "gnustl_static". Perhaps because of others include like "cocosd2-x".

So following the tuto "http://www.cryptopp.com/wiki/Android_(Command_Line)" you must change the script "setenv-android.sh" to have a result like this:

    ANDROID_STL_INC: /Users/toto/Developer/NDKs/AndroidNDKs/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/
    ANDROID_STL_LIB: /Users/toto/Developer/NDKs/AndroidNDKs/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/libgnustl_static.a

and also move the files (just for the compilation)

    /Users/toto/Developer/NDKs/AndroidNDKs/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include/bits 

in

    /Users/toto/Developer/NDKs/AndroidNDKs/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/bits

otherwise there are compilation problems...

Ouf!

Altri suggerimenti

I think there are a couple problems with your answer.

First, when multiple libraries use the standard runtimes, you must use the shared object version and not the static version. That's covered in ANDROID_NDK_ROOT/docs/CPLUSPLUS-SUPPORT.html.

Second, you probably have a problem with library load order. Static linking makes it go away because references to std::_Filebuf_base::_M_write(char*, int) (and friends) are resolved at compile time, and not link/load time. To fix this, you must load libstlport_shared.so (or libgnustl_shared.so) first, and then load libcryptopp.so second.

If you load libcryptopp.so first, then there is no runtime loaded into the process to resolve std::_Filebuf_base::_M_write(char*, int) (and friends). That's covered under the wiki page with the LD_PRELOAD tricks.

To fix it in Android Java, you would perform the following. See Is -rpath working? for details.

static {
    System.loadLibrary("stlport_shared");
    System.loadLibrary("cryptopp");
}

The Crypto+++ Andrid wiki page has been updated: http://www.cryptopp.com/wiki/Android_(ommand_Line)#Android_Activity.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top