【问题标题】:Error while building v8 in android embedded在嵌入的android中构建v8时出错
【发布时间】:2019-05-28 09:38:14
【问题描述】:

我尝试在我的 Android NDK 项目中将 v8 7.6.90 作为静态库导入,但在链接过程中失败。

这是我用于 v8 构建的 args.gn 配置:

android_unstripped_runtime_outputs = true
v8_use_external_startup_data = false
is_debug = false
symbol_level = 1
target_cpu = "arm"
target_os = "android"
use_goma = false
v8_enable_i18n_support = false
v8_static_library = true
is_component_build = false
v8_monolithic = true
v8_android_log_stdout = true

它确实编译并在编译后给了我一个libv8_monolith.a,然后我开始设置我的Android项目。

CMakeLists.txt:

cmake_minimum_required(VERSION 3.4.1)
add_library(v8 STATIC IMPORTED)
set_target_properties( v8 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libv8_monolith.a)
add_library( # Sets the name of the library.
        native-lib

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        ${CMAKE_SOURCE_DIR}/src/main/cpp/native-lib.cpp)

target_include_directories( native-lib PRIVATE ${CMAKE_SOURCE_DIR}/libs/include)

find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)

target_link_libraries( # Specifies the target library.
        native-lib
        v8
        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})

build.gradle:

externalNativeBuild {
    cmake {
        cppFlags "-std=c++0x"
    }
}
ndk {
    abiFilters "armeabi-v7a"
}

native-lib.cpp 在https://chromium.googlesource.com/v8/v8/+/master/samples/hello-world.cc 中运行相同的示例

但是ld总是报错:

../../src/compiler/graph-visualizer.cc:0: error: undefined reference to 'vtable for std::__1::basic_ios<char, std::__1::char_traits<char> >'
/Users/fredguo/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
error: undefined reference to 'v8::platform::NewDefaultPlatform(int, v8::platform::IdleTaskSupport, v8::platform::InProcessStackDumping, std::__ndk1::unique_ptr<v8::TracingController, std::__ndk1::default_delete<v8::TracingController> >)'

我试图 objdump 我的 libv8_monolith.a:

objdump -D app/libs/armeabi-v7a/libv8_monolith.a | grep NewDefault

Disassembly of section .text._ZN2v88platform18NewDefaultPlatformEiNS0_15IdleTaskSupportENS0_21InProcessStackDumpingENSt3__110unique_ptrINS_17TracingControllerENS3_14default_deleteIS5_EEEE:
_ZN2v88platform18NewDefaultPlatformEiNS0_15IdleTaskSupportENS0_21InProcessStackDumpingENSt3__110unique_ptrINS_17TracingControllerENS3_14default_deleteIS5_EEEE:
       4:       81 b0 01 2b     blhs    #442884 <_ZN2v88platform18NewDefaultPlatformEiNS0_15IdleTaskSupportENS0_21InProcessStackDumpingENSt3__110unique_ptrINS_17TracingControllerENS3_14default_deleteIS5_EEEE+0x6C210>
Disassembly of section .rel.text._ZN2v88platform18NewDefaultPlatformEiNS0_15IdleTaskSupportENS0_21InProcessStackDumpingENSt3__110unique_ptrINS_17TracingControllerENS3_14default_deleteIS5_EEEE:
.rel.text._ZN2v88platform18NewDefaultPlatformEiNS0_15IdleTaskSupportENS0_21InProcessStackDumpingENSt3__110unique_ptrINS_17TracingControllerENS3_14default_deleteIS5_EEEE:
Disassembly of section .ARM.exidx.text._ZN2v88platform18NewDefaultPlatformEiNS0_15IdleTaskSupportENS0_21InProcessStackDumpingENSt3__110unique_ptrINS_17TracingControllerENS3_14default_deleteIS5_EEEE:
.ARM.exidx.text._ZN2v88platform18NewDefaultPlatformEiNS0_15IdleTaskSupportENS0_21InProcessStackDumpingENSt3__110unique_ptrINS_17TracingControllerENS3_14default_deleteIS5_EEEE:
Disassembly of section .rel.ARM.exidx.text._ZN2v88platform18NewDefaultPlatformEiNS0_15IdleTaskSupportENS0_21InProcessStackDumpingENSt3__110unique_ptrINS_17TracingControllerENS3_14default_deleteIS5_EEEE:
.rel.ARM.exidx.text._ZN2v88platform18NewDefaultPlatformEiNS0_15IdleTaskSupportENS0_21InProcessStackDumpingENSt3__110unique_ptrINS_17TracingControllerENS3_14default_deleteIS5_EEEE:
Disassembly of section .text._ZN2v811ArrayBuffer9Allocator19NewDefaultAllocatorEv:
_ZN2v811ArrayBuffer9Allocator19NewDefaultAllocatorEv:
Disassembly of section .rel.text._ZN2v811ArrayBuffer9Allocator19NewDefaultAllocatorEv:
.rel.text._ZN2v811ArrayBuffer9Allocator19NewDefaultAllocatorEv:
Disassembly of section .ARM.exidx.text._ZN2v811ArrayBuffer9Allocator19NewDefaultAllocatorEv:
.ARM.exidx.text._ZN2v811ArrayBuffer9Allocator19NewDefaultAllocatorEv:
Disassembly of section .rel.ARM.exidx.text._ZN2v811ArrayBuffer9Allocator19NewDefaultAllocatorEv:
.rel.ARM.exidx.text._ZN2v811ArrayBuffer9Allocator19NewDefaultAllocatorEv:

_ZN2v88platform18NewDefaultPlatformEiNS0_15IdleTaskSupportENS0_21InProcessStackDumpingENSt3__110unique_ptrINS_17TracingControllerENS3_14default_deleteIS5_EEEE

应该是

v8::platform::NewDefaultPlatform(int, v8::platform::IdleTaskSupport, v8::platform::InProcessStackDumping, std::__1::unique_ptr&lt;v8::TracingController, std::__1::default_delete&lt;v8::TracingController&gt; &gt;)

但是,在错误消息中,ld 尝试查找 std::__ndk1::unique_ptr&lt;v8::TracingController, std::__ndk1::default_delete&lt;v8::TracingController&gt; &gt;)

我认为他们有不同的命名空间,但我该如何解决这个问题?我在这里https://groups.google.com/forum/#!topic/v8-users/Jb1VSouy2Z0 发现了类似的问题,但该解决方案对我不起作用。

【问题讨论】:

  • 相信在args.gn中加入use_custom_libcxx=false就能解决问题,见How to use linked libraries compiled with libc++ libstdc++ mixed
  • 我也面临类似的问题。我试过 use_custom_libcxx=false 标志,但这对我没有帮助。有什么解决办法吗?这是我的错误日志。 SampleNDK/app/src/main/cpp/hello-jni.cpp:42: 错误: 未定义引用 'v8::platform::NewDefaultPlatform(int, v8::platform::IdleTaskSupport, v8::platform::InProcessStackDumping, std::__ndk1::unique_ptr >)' ../../buildtools/third_party/libc++/trunk/include/memory:3586: 错误:未定义引用 'std::__1::__shared_weak_count::__release_weak()'
  • @BABASHANKER 我按照文档并设法降级到 7.2 并编译。但是我没有发现7.2以上的运气。这是我在 7.2 中的 args.gnis_debug = true target_cpu = "arm" target_os = "android" v8_android_log_stdout = false is_component_build = false android_unstripped_runtime_outputs = false v8_enable_backtrace = true v8_enable_slow_dchecks = true v8_optimized_debug = false use_goma = false v8_monolithic = true v8_use_external_startup_data = false P.S 我不知道如何在评论中换行,抱歉格式不好:P

标签: android c++ android-ndk v8


【解决方案1】:

尝试修改v8/buildtools/third_party/libc++/trunk/include/__config中的命名空间宏:

_LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)_LIBCPP_CONCAT(__ndk,_LIBCPP_ABI_VERSION)

希望这会有所帮助。

【讨论】:

  • 这是正确的答案。对于一些 v8 7.2+ 和 v8 8.0,我也必须这样做。
猜你喜欢
  • 1970-01-01
  • 2019-04-22
  • 1970-01-01
  • 1970-01-01
  • 2019-01-02
  • 2022-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多