문제

I have two shared libs: lib1 and lib2. lib1 is prebuilded to lib2.

I have Class in lib1:

#include <android/log.h>

#include "stdlib.h"
#include <string>

class Foo
{
public:
    Foo()
    {
        __android_log_print(ANDROID_LOG_VERBOSE, "Two Libs", "Foo::Foo()"); 
    }

    ~Foo();

private:
    std::string str;
};

destructor defined in .cpp file.

#include "first.h"

Foo::~Foo()
{
    __android_log_print(ANDROID_LOG_VERBOSE, "Two Libs", "Foo::~Foo()");    
}

Than I use this class in lib2:

#include <string.h>
#include <jni.h>
#include <android/log.h>

#include "first.h"

extern "C" 
{

JNIEXPORT void JNICALL Java_com_example_twolibs_TwoLibs_nativeMethod( JNIEnv* env )
{
    __android_log_print(ANDROID_LOG_VERBOSE, "Two Libs", "Test std::string bug 1");

    Foo* newFoo = new Foo();

    __android_log_print(ANDROID_LOG_VERBOSE, "Two Libs", "Test std::string bug 2");

    delete newFoo;

    __android_log_print(ANDROID_LOG_VERBOSE, "Two Libs", "Test std::string bug 3"); 

    return;
}

}

log:

09-09 12:48:14.089: V/Two Libs(13512): Test std::string bug 1
09-09 12:48:14.089: V/Two Libs(13512): Foo::Foo()
09-09 12:48:14.089: V/Two Libs(13512): Test std::string bug 2
09-09 12:48:14.089: V/Two Libs(13512): Foo::~Foo()

If I delete std::string - no crash occurs. So the problem looks like in std::string destructor.

If I define class in lib2 or use it only in lib1 - no crash occurs

If I define destructor in header only - no crash occurs

I use ndk-r8b. The same problem on crystax-r7. Build on Windows via CygWin.

crash log:

09-09 12:48:14.199: I/DEBUG(10548): Build fingerprint: 'samsung/GT-S5660/GT-S5660:2.3.3/GINGERBREAD/XXKPK:user/release-keys'
09-09 12:48:14.199: I/DEBUG(10548): pid: 13512, tid: 13512  >>> com.example.twolibs <<<
09-09 12:48:14.199: I/DEBUG(10548): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
09-09 12:48:14.209: I/DEBUG(10548):  r0 deadbaad  r1 0000000c  r2 00000027  r3 00000000
09-09 12:48:14.209: I/DEBUG(10548):  r4 00000080  r5 afd46688  r6 0000a000  r7 4428fce8
09-09 12:48:14.209: I/DEBUG(10548):  r8 beb75470  r9 4428fce0  10 4428fcc8  fp 44ff5970
09-09 12:48:14.209: I/DEBUG(10548):  ip ffffffff  sp beb753e0  lr afd19385  pc afd15f00  cpsr 00000030
09-09 12:48:14.209: I/DEBUG(10548):  d0  3f8000003f800000  d1  3ff0000040000000
09-09 12:48:14.209: I/DEBUG(10548):  d2  bfd3441350baf6de  d3  c1493000c1323800
09-09 12:48:14.209: I/DEBUG(10548):  d4  4900000040dcb000  d5  000000000006e580
09-09 12:48:14.209: I/DEBUG(10548):  d6  4515a00000000800  d7  40800000c48ee000
09-09 12:48:14.219: I/DEBUG(10548):  d8  0000000000000000  d9  0000000000000000
09-09 12:48:14.219: I/DEBUG(10548):  d10 0000000000000000  d11 0000000000000000
09-09 12:48:14.219: I/DEBUG(10548):  d12 0000000000000000  d13 0000000000000000
09-09 12:48:14.219: I/DEBUG(10548):  d14 0000000000000000  d15 0000000000000000
09-09 12:48:14.219: I/DEBUG(10548):  scr 60000012
09-09 12:48:14.279: I/DEBUG(10548):          #00  pc 00015f00  /system/lib/libc.so
09-09 12:48:14.279: I/DEBUG(10548):          #01  pc 00013862  /system/lib/libc.so
09-09 12:48:14.279: I/DEBUG(10548): code around pc:
09-09 12:48:14.279: I/DEBUG(10548): afd15ee0 68241c23 d1fb2c00 68dae027 d0042a00 
09-09 12:48:14.279: I/DEBUG(10548): afd15ef0 20014d18 6028447d 48174790 24802227 
09-09 12:48:14.279: I/DEBUG(10548): afd15f00 f7f57002 2106eb56 ec92f7f6 0563aa01 
09-09 12:48:14.279: I/DEBUG(10548): afd15f10 60932100 91016051 1c112006 e818f7f6 
09-09 12:48:14.279: I/DEBUG(10548): afd15f20 2200a905 f7f62002 f7f5e824 2106eb42 
09-09 12:48:14.279: I/DEBUG(10548): code around lr:
09-09 12:48:14.279: I/DEBUG(10548): afd19364 b0834a0d 589c447b 26009001 686768a5 
09-09 12:48:14.279: I/DEBUG(10548): afd19374 220ce008 2b005eab 1c28d003 47889901 
09-09 12:48:14.279: I/DEBUG(10548): afd19384 35544306 d5f43f01 2c006824 b003d1ee 
09-09 12:48:14.279: I/DEBUG(10548): afd19394 bdf01c30 000281b8 ffffff88 1c0fb5f0 
09-09 12:48:14.279: I/DEBUG(10548): afd193a4 43551c3d a904b087 1c16ac01 604d9004 
09-09 12:48:14.279: I/DEBUG(10548): stack:
09-09 12:48:14.279: I/DEBUG(10548):     beb753a0  00000015  
09-09 12:48:14.279: I/DEBUG(10548):     beb753a4  afd18417  /system/lib/libc.so
09-09 12:48:14.279: I/DEBUG(10548):     beb753a8  afd4272c  
09-09 12:48:14.279: I/DEBUG(10548):     beb753ac  afd426d8  
09-09 12:48:14.279: I/DEBUG(10548):     beb753b0  00000000  
09-09 12:48:14.279: I/DEBUG(10548):     beb753b4  afd19385  /system/lib/libc.so
09-09 12:48:14.279: I/DEBUG(10548):     beb753b8  802182c0  /system/lib/libdvm.so
09-09 12:48:14.279: I/DEBUG(10548):     beb753bc  afd183e9  /system/lib/libc.so
09-09 12:48:14.279: I/DEBUG(10548):     beb753c0  4428fc50  
09-09 12:48:14.279: I/DEBUG(10548):     beb753c4  00000000  
09-09 12:48:14.279: I/DEBUG(10548):     beb753c8  afd46688  
09-09 12:48:14.279: I/DEBUG(10548):     beb753cc  0000a000  
09-09 12:48:14.279: I/DEBUG(10548):     beb753d0  4428fce8  
09-09 12:48:14.279: I/DEBUG(10548):     beb753d4  afd18687  /system/lib/libc.so
09-09 12:48:14.279: I/DEBUG(10548):     beb753d8  df002777  
09-09 12:48:14.279: I/DEBUG(10548):     beb753dc  e3a070ad  
09-09 12:48:14.279: I/DEBUG(10548): #00 beb753e0  ffffffff  
09-09 12:48:14.279: I/DEBUG(10548):     beb753e4  7fffffd2  
09-09 12:48:14.279: I/DEBUG(10548):     beb753e8  afd46628  
09-09 12:48:14.279: I/DEBUG(10548):     beb753ec  afd11020  /system/lib/libc.so
09-09 12:48:14.279: I/DEBUG(10548):     beb753f0  80d1cf00  
09-09 12:48:14.279: I/DEBUG(10548):     beb753f4  fffffbdf  
09-09 12:48:14.279: I/DEBUG(10548):     beb753f8  000000da  
09-09 12:48:14.279: I/DEBUG(10548):     beb753fc  afd46470  
09-09 12:48:14.279: I/DEBUG(10548):     beb75400  000001b4  
09-09 12:48:14.279: I/DEBUG(10548):     beb75404  afd13867  /system/lib/libc.so
09-09 12:48:14.279: I/DEBUG(10548): #01 beb75408  afd46470  
09-09 12:48:14.279: I/DEBUG(10548):     beb7540c  afd13867  /system/lib/libc.so
09-09 12:48:14.279: I/DEBUG(10548):     beb75410  802182c0  /system/lib/libdvm.so
09-09 12:48:14.279: I/DEBUG(10548):     beb75414  0000cec8  
09-09 12:48:14.279: I/DEBUG(10548):     beb75418  00000000  
09-09 12:48:14.279: I/DEBUG(10548):     beb7541c  903884f9  
09-09 12:48:14.279: I/DEBUG(10548):     beb75420  000000da  
09-09 12:48:14.279: I/DEBUG(10548):     beb75424  80c1ce44  
09-09 12:48:14.289: I/DEBUG(10548):     beb75428  000f1200  
09-09 12:48:14.289: I/DEBUG(10548):     beb7542c  80d1cf00  
09-09 12:48:14.289: I/DEBUG(10548):     beb75430  4428fce8  
09-09 12:48:14.289: I/DEBUG(10548):     beb75434  afd14779  /system/lib/libc.so
09-09 12:48:14.289: I/DEBUG(10548):     beb75438  80c1ce44  
09-09 12:48:14.289: I/DEBUG(10548):     beb7543c  80c08097  /mnt/asec/com.example.twolibs-1/lib/libfirst.so
09-09 12:48:14.289: I/DEBUG(10548):     beb75440  00000000  
09-09 12:48:14.289: I/DEBUG(10548):     beb75444  460247e3  
09-09 12:48:14.289: I/DEBUG(10548):     beb75448  000f1200  
09-09 12:48:14.289: I/DEBUG(10548):     beb7544c  00000000  

I can attach sample project if it alloved on this forum.

도움이 되었습니까?

해결책

I tried this with NDK-r8b on cygwin, and it worked just fine, with minimal cosmetic changes. It works correctly on Andorid 2.2 with APP_STL=gnustl_static or gnustl_shared or stlport_static or stlport_shared. Note that you need to insert System.loadLibrary("gnustl_shared") or System.loadLibrary("stlport_shared") into TwoLibs.java file.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top