我一直把头发拉过来。我正在开发64位Ubuntu 12.04。我创建了一个嵌入了V8的原生Android应用程序,但重新启动计算机后,它不再与V8链接了!我已经尝试重新安装ndk并重新编译V8,但无济于事。链接器似乎包含静态库,但未在其中找到符号。我用nm检查了,符号似乎在那里。
当我运行ndk_build时,我得到以下输出:
$ 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 to '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 to '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 to '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 to '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 to '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 to '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 to '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 to '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 to '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 to 'v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::String::NewStringType, int)'
... etc ...
特别是,这一行告诉我包含* .a文件:
/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
我的Android.mk看起来像这样:
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)
LOCAL_STATIC_LIBRARIES顺序是凭经验确定的。我更多地摆弄它,但无济于事。我甚至尝试过LOCAL_WHOLE_STATIC_LIBRARIES。我用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
我不是名字改变的专家,但似乎他们在那里。这些值都是零,但我相信这是正常的。
所以我想,也许链接器不理解静态库,它无声地失败 但是,如何检查链接器无法获取符号的原因?
答案 0 :(得分:4)
我终于在朋友的帮助下解决了这个问题。首先,我尝试了一种解决方法,在那里我尝试将V8链接为共享库,但由于NDK native activity interface I'm using turned out to be incompatible with loading additional shared objects,因此效果不佳。
我的静态库有两个不同的问题。第一个也是最重要的一个是V8构建的静态库不适合链接。您可以使用以下方法检查:
ar x [static_library.a]
通常会从库中提取* .o对象。在这种情况下,它报告:
`x' cannot be used on thin archives
精简存档只是对* .o文件的绝对路径的一组引用,而不是实际内容。这就解释了为什么我的构建停止工作,我在V8构建树中移动或删除了原始的* .o文件。奇怪的是,链接器对此保持沉默。
创建静态库目前不是V8中的构建选项。值得庆幸的是,this guy has a patch用于在V8中创建适当的静态库。
在我这样做后,应用程序仍然没有链接,因为我第一次复制了错误的文件。事实证明,静态库也是为主机架构而构建的(不要问我为什么),而且我不小心复制了这些库。我了解到你可以使用:
file objectfile.o
看看它是什么架构。因此我发现我的静态库是i386而不是arm。因此,链接器正在跳过这些文件,因为架构不匹配(您可以在静态库中混合架构)。
这是我根据Curu Wong的补丁对V8 3.27.28进行的V8补丁。我会尝试让这个补丁得到承诺。补丁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)',
],
补丁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)',
],