3

我的代码在这里崩溃:

void setText(const string & s) 
{ 
    needsReload = true; 
    _text = s; //<-- SIGSEGV here
}

_text是一个 std::string

这完全没有意义。this_text并且s在有效内存中。我不能尝试portstl,因为我需要例外。没有什么可以出错的。我目前正在为 armeabi-v7a 编译。有什么建议么?

经过一番摆弄后,我发现每当我将某些东西分配给事先是空字符串的字符串时,它就会崩溃。我认为这与我的 libstdc++ 有关。这是我的编译和链接标志:

[ 50%] Building CXX object CMakeFiles/Mathrix.dir/main.cpp.o
/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++   -DMathrix_EXPORTS -DANDROID -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ --sysroot=/opt/android-ndk/platforms/android-9/arch-arm -fsigned-char -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fdata-sections -ffunction-sections -fPIC -Wno-psabi -frtti -fexceptions -marm -Os -finline-limit=64 -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG -DDEBUG -fPIC -isystem /opt/android-ndk/platforms/android-9/arch-arm/usr/include -isystem /opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.6/include -isystem /opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -I/home/da_petcu21/src/Porkholt/Examples/Mathrix/../../Engine/include -I/home/da_petcu21/src/Porkholt/Examples/Mathrix/../../Engine/../Externals/lua/src -I/home/da_petcu21/src/Porkholt/Examples/Mathrix/../../Engine/../Externals/libpng -I/home/da_petcu21/src/Porkholt/Examples/Mathrix/../../Engine/../Externals/zlib -I/home/da_petcu21/src/Porkholt/Examples/Mathrix/../../Engine/../Externals/uremote/include -I/home/da_petcu21/src/Porkholt/Examples/Mathrix/../../Engine/../Externals/openal-soft/include    -o CMakeFiles/Mathrix.dir/main.cpp.o -c /home/da_petcu21/src/Porkholt/Examples/Mathrix/main.cpp
Linking CXX shared library ../libs/armeabi-v7a/libMathrix.so
/usr/bin/cmake -E cmake_link_script CMakeFiles/Mathrix.dir/link.txt --verbose=Yes
/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++  -fPIC --sysroot=/opt/android-ndk/platforms/android-9/arch-arm -fsigned-char -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fdata-sections -ffunction-sections -fPIC -Wno-psabi -frtti -fexceptions -marm -Os -finline-limit=64 -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG -DDEBUG -Wl,--fix-cortex-a8 -Wl,--gc-sections -Wl,--no-undefined   -shared -Wl,-soname,libMathrix.so -o ../libs/armeabi-v7a/libMathrix.so CMakeFiles/Mathrix.dir/main.cpp.o -L/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/user/libs/armeabi-v7a -L/home/da_petcu21/src/Porkholt/Examples/Mathrix/build-android/armeabi-v7a/CMakeFiles/ndklibs/armeabi-v7a -L/home/da_petcu21/src/Porkholt/Examples/Mathrix/build-android/libs/armeabi-v7a -lPorkholt -llua -Wl,-rpath,/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/user/libs/armeabi-v7a:/home/da_petcu21/src/Porkholt/Examples/Mathrix/build-android/armeabi-v7a/CMakeFiles/ndklibs/armeabi-v7a:/home/da_petcu21/src/Porkholt/Examples/Mathrix/build-android/libs/armeabi-v7a 

我正在使用的构建脚本复制libgnustl_static/home/da_petcu21/src/Porkholt/Examples/Mathrix/build-android/armeabi-v7a/CMakeFiles/ndklibs/armeabi-v7a/libstdc++.a

我怀疑它使用了/opt/android-ndk/platforms/android-9/arm/lib那个

4

1 回答 1

4

问题是 stl 与我的每个库都静态链接,因此创建了需要共享的某些全局变量的副本。(请参阅Can't load native shared library with dependencies in a native Activity app以查看我的 apk 的库布局)。

为了将来参考,这里有一个很好的解释为什么会发生这种情况:http ://www.trilithium.com/johan/2005/06/static-libstdc/

我设法通过简单地动态链接stl来解决这个问题。

于 2012-09-26T09:30:06.617 回答