The following code will crash at vector desconcrutor if I build the code for Android x86_64 with ndk-build(x86 worked well).
hello.cpp
#include <vector>
#include <stdio.h>
using namespace std;
int main(int argc, char* argv[])
{
vector<int> vec;
vec.push_back(11);
vec.clear();
vector<int> vec2(vec.size());
return 0;
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello
LOCAL_SRC_FILES := hello.cpp
include $(BUILD_EXECUTABLE)
Application.mk
APP_ABI := x86_64
APP_STL := stlport_static
It is weird. The value of vec.size() equals to 0. If I change the code as follows:
vector<int> vec2(0);
the app will not crash. The issue seems to be caused by compiler optimization. CFLAG -O2 is used by default. If I add another CFLAG, such as -O0 after it, the app will not crash either.
Does anybody know why?
Thanks!
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/80a8af34-84b4-4d27-9418-cb92b358d6cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/ed9fc32e-9034-4a8a-abb7-f575f9a9fac5%40googlegroups.com.