c++ - Android NDK linking V8 static library: cannot find symbols, but they are there -



c++ - Android NDK linking V8 static library: cannot find symbols, but they are there -

i've been pulling hair out on one. developing on ubuntu 12.04 64-bit. created native android app v8 embedded in it, after rebooting computer, doesn't link v8 anymore! i've tried reinstalling ndk , recompiling v8, no avail. appears linker include static libraries, doesn't find symbols in them. checked nm, , symbols appear there.

when run ndk_build, next output:

$ ndk-build v=1 rm -f ./libs/armeabi/lib*.so ./libs/armeabi-v7a/lib*.so ./libs/armeabi-v7a-hard/lib*.so ./libs/mips/lib*.so ./libs/x86/lib*.so rm -f ./libs/armeabi/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/armeabi-v7a-hard/gdbserver ./libs/mips/gdbserver ./libs/x86/gdbserver rm -f ./libs/armeabi/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/armeabi-v7a-hard/gdb.setup ./libs/mips/gdb.setup ./libs/x86/gdb.setup [armeabi] compile++ thumb: native-activity <= main.cpp /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -mmd -mp -mf ./obj/local/armeabi/objs/native-activity/main.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -fno-rtti -mthumb -os -g -dndebug -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -ijni/include -i/home/schooten/bin/packages/android-ndk-r9d/sources/android/native_app_glue -i/home/schooten/bin/packages/android-ndk-r9d/sources/cxx-stl/system/include -ijni -dandroid -wa,--noexecstack -wformat -werror=format-security -i/home/schooten/bin/packages/android-ndk-r9d/platforms/android-9/arch-arm/usr/include -c jni/main.cpp -o ./obj/local/armeabi/objs/native-activity/main.o [armeabi] compile thumb : android_native_app_glue <= android_native_app_glue.c /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -mmd -mp -mf ./obj/local/armeabi/objs/android_native_app_glue/android_native_app_glue.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -mthumb -os -g -dndebug -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -i/home/schooten/bin/packages/android-ndk-r9d/sources/android/native_app_glue -dandroid -wa,--noexecstack -wformat -werror=format-security -i/home/schooten/bin/packages/android-ndk-r9d/platforms/android-9/arch-arm/usr/include -c /home/schooten/bin/packages/android-ndk-r9d/sources/android/native_app_glue/android_native_app_glue.c -o ./obj/local/armeabi/objs/android_native_app_glue/android_native_app_glue.o [armeabi] staticlibrary : libandroid_native_app_glue.a rm -f obj/local/armeabi/libandroid_native_app_glue.a /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar crsd ./obj/local/armeabi/libandroid_native_app_glue.a ./obj/local/armeabi/objs/android_native_app_glue/android_native_app_glue.o [armeabi] staticlibrary : libstdc++.a rm -f obj/local/armeabi/libstdc++.a /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar crsd ./obj/local/armeabi/libstdc++.a [armeabi] sharedlibrary : libnative-activity.so /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -wl,-soname,libnative-activity.so -shared --sysroot=/home/schooten/bin/packages/android-ndk-r9d/platforms/android-9/arch-arm ./obj/local/armeabi/objs/native-activity/main.o ./obj/local/armeabi/libandroid_native_app_glue.a jni/lib/libv8_libbase.arm.a jni/lib/libv8_nosnapshot.a jni/lib/libv8_base.a jni/lib/libstlport_static.a ./obj/local/armeabi/libstdc++.a -lgcc -no-canonical-prefixes -wl,--no-undefined -wl,-z,noexecstack -wl,-z,relro -wl,-z,now -l/home/schooten/bin/packages/android-ndk-r9d/platforms/android-9/arch-arm/usr/lib -llog -landroid -legl -lglesv1_cm -llog -lstdc++ -lc -lm -o ./obj/local/armeabi/libnative-activity.so /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/native-activity/main.o: in function __clearcolor(v8::functioncallbackinfo<v8::value> const&):jni/main.cpp:88: error: undefined reference 'v8::value::int32value() const' /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/native-activity/main.o: in function __clearcolor(v8::functioncallbackinfo<v8::value> const&):jni/main.cpp:89: error: undefined reference 'v8::value::int32value() const' /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/native-activity/main.o: in function __clearcolor(v8::functioncallbackinfo<v8::value> const&):jni/main.cpp:90: error: undefined reference 'v8::value::int32value() const' /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/native-activity/main.o: in function __clearcolor(v8::functioncallbackinfo<v8::value> const&):jni/main.cpp:91: error: undefined reference 'v8::value::int32value() const' /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/native-activity/main.o: in function run_javascript(char*):jni/main.cpp:101: error: undefined reference 'v8::isolate::new()' /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/native-activity/main.o: in function run_javascript(char*):jni/include/v8.h:4045: error: undefined reference 'v8::isolate::enter()' /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/native-activity/main.o: in function run_javascript(char*):jni/main.cpp:104: error: undefined reference 'v8::handlescope::handlescope(v8::isolate*)' /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/native-activity/main.o: in function run_javascript(char*):jni/main.cpp:108: error: undefined reference 'v8::objecttemplate::new(v8::isolate*)' /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/native-activity/main.o: in function run_javascript(char*):jni/main.cpp:110: error: undefined reference 'v8::objecttemplate::new(v8::isolate*)' /home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/native-activity/main.o: in function run_javascript(char*):jni/main.cpp:112: error: undefined reference 'v8::string::newfromutf8(v8::isolate*, char const*, v8::string::newstringtype, int)' ... etc ...

in particular, line tells me *.a files included:

/home/schooten/bin/packages/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -wl,-soname,libnative-activity.so -shared --sysroot=/home/schooten/bin/packages/android-ndk-r9d/platforms/android-9/arch-arm ./obj/local/armeabi/objs/native-activity/main.o ./obj/local/armeabi/libandroid_native_app_glue.a jni/lib/libv8_libbase.arm.a jni/lib/libv8_nosnapshot.a jni/lib/libv8_base.a jni/lib/libstlport_static.a ./obj/local/armeabi/libstdc++.a -lgcc -no-canonical-prefixes -wl,--no-undefined -wl,-z,noexecstack -wl,-z,relro -wl,-z,now -l/home/schooten/bin/packages/android-ndk-r9d/platforms/android-9/arch-arm/usr/lib -llog -landroid -legl -lglesv1_cm -llog -lstdc++ -lc -lm -o ./obj/local/armeabi/libnative-activity.so

my android.mk looks this:

local_path := $(call my-dir) include $(clear_vars) local_module := stlport local_module_filename := stlport_static local_src_files := lib/libstlport_static.a include $(prebuilt_static_library) include $(clear_vars) local_module := v8_base local_module_filename := v8_base_static local_src_files := lib/libv8_base.a include $(prebuilt_static_library) include $(clear_vars) local_module := v8_nosnapshot local_module_filename := v8_nosnapshot_static local_src_files := lib/libv8_nosnapshot.a include $(prebuilt_static_library) include $(clear_vars) local_module := v8_libbase local_module_filename := v8_libbase_static local_src_files := lib/libv8_libbase.arm.a include $(prebuilt_static_library) include $(clear_vars) local_module := native-activity local_src_files := main.cpp local_ldlibs := -llog -landroid -legl -lglesv1_cm local_static_libraries := android_native_app_glue v8_libbase v8_nosnapshot v8_base stlport local_c_includes := $(local_path)/include include $(build_shared_library) $(call import-module,android/native_app_glue)

the local_static_libraries order determined empirically. fiddled more, no avail. tried local_whole_static_libraries. checked existence of symbols nm:

arm-linux-gnueabi-nm jni/lib/libv8_base.a | grep int32value u _znk2v85value10int32valueev 00000000 t _znk2v85value10int32valueev u _znk2v85value10int32valueev arm-linux-gnueabi-nm jni/lib/libv8_base.a | grep utf8value 00000000 t _zn2v86string9utf8valuec1ens_6handleins_5valueeee 00000000 t _zn2v86string9utf8valuec2ens_6handleins_5valueeee 00000000 t _zn2v86string9utf8valued1ev 00000000 t _zn2v86string9utf8valued2ev u _zn2v86string9utf8valuec1ens_6handleins_5valueeee u _zn2v86string9utf8valued1ev u _zn2v86string9utf8valuec1ens_6handleins_5valueeee u _zn2v86string9utf8valued1ev u _zn2v86string9utf8valuec1ens_6handleins_5valueeee u _zn2v86string9utf8valued1ev u _zn2v86string9utf8valuec1ens_6handleins_5valueeee u _zn2v86string9utf8valued1ev u _zn2v86string9utf8valuec1ens_6handleins_5valueeee u _zn2v86string9utf8valued1ev

i no expert @ name munging, appears there. values zeroes, believe normal.

so figured, maybe linker doesn't understand static library, , fails silently. how check why linker failing pick symbols?

i fixed it, help of friend. first tried workaround tried link v8 shared library, didn't turn out because ndk native activity interface i'm using turned out incompatible loading additional shared objects.

there 2 different issues going on static libraries. first , of import 1 static libraries built v8 not suitable linking. can check using:

ar x [static_library.a]

which extract *.o objects library. in case, reported:

`x' cannot used on lean archives

a lean archive set of references absolute paths of *.o files, , no actual content. explains why build stopped working @ 1 point moved or deleted original *.o files v8 build tree. strangely, linker kept silent that.

creating static libraries not build alternative in v8. thankfully, this guy has patch creating proper static libraries in v8.

the app still didn't link after did that, because copied wrong files first time round. turned out, static libraries built host architecture (don't inquire me why), , accidentally copied those. learned can use:

file objectfile.o

to see architecture is. hence found static libraries i386 , not arm. so, linker skipping these files, because architecture didn't match (you can mix architectures in static library).

here v8 patch made v8 3.27.28 based on patch curu wong. seek patch committed. patch 1:

~/work/javascript/engines/v8-trunk/tools/gyp$ diff -u v8.gyp.orig v8.gyp --- v8.gyp.orig 2014-06-18 21:09:59.368336736 +0200 +++ v8.gyp 2014-06-18 21:12:20.264331660 +0200 @@ -108,6 +108,7 @@ { 'target_name': 'v8_snapshot', 'type': 'static_library', + 'standalone_static_library': 1, 'conditions': [ ['want_separate_host_toolset==1', { 'toolsets': ['host', 'target'], @@ -180,6 +181,7 @@ { 'target_name': 'v8_nosnapshot', 'type': 'static_library', + 'standalone_static_library': 1, 'dependencies': [ 'v8_base', ], @@ -237,6 +239,7 @@ { 'target_name': 'v8_base', 'type': 'static_library', + 'standalone_static_library': 1, 'dependencies': [ 'v8_libbase.<(v8_target_arch)', ],

patch 2:

~/work/javascript/engines/v8-trunk/third_party/icu$ diff -u icu.gyp.orig icu.gyp --- icu.gyp.orig 2014-06-18 21:10:22.060335920 +0200 +++ icu.gyp 2014-06-18 21:15:06.468325674 +0200 @@ -56,6 +56,7 @@ { 'target_name': 'icudata', 'type': 'static_library', + 'standalone_static_library': 1, 'defines': [ 'u_hide_data_symbol', ], @@ -141,6 +142,11 @@ { 'target_name': 'icui18n', 'type': '<(component)', + 'conditions': [ + [ 'component!="shared_library"', { + 'standalone_static_library': 1, + }], + ], 'sources': [ '<@(icui18n_sources)', ], @@ -241,6 +247,11 @@ { 'target_name': 'icuuc', 'type': '<(component)', + 'conditions': [ + [ 'component!="shared_library"', { + 'standalone_static_library': 1, + }], + ], 'sources': [ '<@(icuuc_sources)', ],

c++ linker android-ndk embedded-v8

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -