【问题标题】:Android NDK clang compiler can't find std::make_uniqueAndroid NDK clang 编译器找不到 std::make_unique
【发布时间】:2015-03-12 19:10:16
【问题描述】:

我正在使用 Android NDK r10d。我的 application.mk 设置如下:

APP_CFLAGS := -DANDROID -DBUILD_OGLES2
APP_CPPFLAGS := $(APP_CFLAGS) -fexceptions -frtti -std=c++14
APP_STL := gnustl_static
APP_ABI := armeabi-v7a
APP_PLATFORM := android-15
NDK_TOOLCHAIN_VERSION := clang

我在我的代码中使用std::make_unique,但它没有编译(说它没有找到)。从 C++14 开始,这个特性应该在 STL 中可用。我做了一些探索,似乎 clang 没有在 NDK 中使用 GNU STL 4.9。如果是,它将可用,因为我在 <memory> 标头中看到它。

我在这里缺少什么?有没有办法将 4.9 GNU STL 与 clang 一起使用?

【问题讨论】:

  • 尝试将-stdlib=libstdc++添加到APP_CPPFLAGS
  • @Praetorian 还是没用 :-( error: no member named 'make_unique' in namespace 'std'
  • 您可以同时获取make_unique elsewhere 的实现。

标签: android c++ android-ndk clang c++14


【解决方案1】:

make_unique 不能通过来自 clang 的 gnustl 获得。您可以尝试改用 LLVM libc++。在你的 Application.mk 中设置它:

APP_STL := c++_static
NDK_TOOLCHAIN_VERSION := clang

编辑: 强制使用 GNU STL 4.9(通过更改android-ndk-r10d/toolchains/*toolchain_name*-clang3.5/setup.mk 内的 TOOLCHAIN_VERSION)会使构建崩溃:

clang++: /s/ndk-toolchain/src/llvm-3.5/llvm/tools/clang/lib/AST/DeclBase.cpp:1293: clang::DeclContext::lookup_result clang::DeclContext::lookup(clang::DeclarationName): Assertion 'DeclKind != Decl::LinkageSpec && "Should not perform lookups into linkage specs!"' failed.

【讨论】:

  • 是的,它在工具链版本 4.9 中可用。
  • 但是 clang 依赖 gcc 4.8 并且将其切换到 4.9 不起作用,请参阅我的编辑。
  • 谢谢。我遇到了“unique_ptr”这个问题,从“stlport_shared”切换到“c++_shared”似乎已经解决了。
猜你喜欢
  • 1970-01-01
  • 2018-11-26
  • 1970-01-01
  • 2012-12-02
  • 2021-07-29
  • 1970-01-01
  • 2015-05-16
  • 2016-10-28
  • 1970-01-01
相关资源
最近更新 更多