我的代码崩溃了:
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
中的那个而不是
答案 0 :(得分:3)
问题是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来解决问题。