且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android NDK链接V8静态库:找不到符号,但它们在那里

更新时间:2023-11-16 20:46:58

在朋友的帮助下,我终于修好了.首先,我尝试了一种解决方法,尝试将 V8 链接为共享库,但结果并不好,因为 我使用的 NDK 原生活动接口与加载其他共享对象不兼容.

I finally fixed it, with help of a friend. First I tried a workaround where I tried to link V8 as a shared library, which didn't turn out well because the NDK native activity interface I'm using turned out to be incompatible with loading additional shared objects.

我的静态库存在两个不同的问题.第一个也是最重要的一点是V8构建的静态库不适合链接.您可以使用以下方法进行检查:

There were two different issues going on with my static libraries. The first and most important one is that the static libraries built by V8 are not suitable for linking. You can check this by using:

ar x [static_library.a]

这通常会从库中提取 *.o 对象.在这种情况下,它报告:

which will normally extract the *.o objects from the library. In this case, it reported:

`x' cannot be used on thin archives

精简存档只是一组对 *.o 文件的绝对路径的引用,没有实际内容.这就解释了为什么我的构建在我从 V8 构建树中移动或删除原始 *.o 文件时停止工作.奇怪的是,链接器对此保持沉默.

A thin archive is just a set of references to the absolute paths of the *.o files, and no actual content. That explains why my build stopped working at one point where I moved or deleted the original *.o files from the V8 build tree. Strangely, the linker kept silent about that.

创建静态库目前不是 V8 中的构建选项.值得庆幸的是,这家伙有一个补丁来创建正确的V8 中的静态库.

Creating static libraries is not currently a build option in V8. Thankfully, this guy has a patch for creating proper static libraries in V8.

在我这样做之后,应用程序仍然没有链接,因为我第一次复制了错误的文件.事实证明,静态库也是为主机架构构建的(不要问我为什么),我不小心复制了这些.我了解到您可以使用:

The app still didn't link after I did that, because I copied the wrong files the first time round. As it turned out, the static libraries are also built for the host architecture (don't ask me why), and I accidentally copied those. I learned that you can use:

file objectfile.o

看看它是什么架构.因此我发现我的静态库是 i386 而不是 arm.因此,链接器跳过了这些文件,因为架构不匹配(您可以在静态库中混合架构).

to see what architecture it is. Hence I found my static libraries were i386 and not arm. So, the linker was skipping these files, because the architecture didn't match (you can mix architectures in a static library).

这是我根据 Curu Wong 的补丁为 V8 3.27.28 制作的 V8 补丁.我将尝试提交此补丁.补丁 1:

Here is the V8 patch that I made to V8 3.27.28 based on the patch by Curu Wong. I will try to get this 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)',
       ],

补丁 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)',
           ],