【问题标题】:Compile C++ program on Android: undefined function assert在 Android 上编译 C++ 程序:未定义的函数断言
【发布时间】:2019-04-17 03:12:51
【问题描述】:

我正在尝试在 Android 上编译我的 C++ 程序,但它无法编译,因为 assert 未定义。

我在网上找到了一些提示,但都没有奏效:

我在 myApplication.mk 中设置了APP_OPTIM=debug

我已经通过参数覆盖设置NDK_DEBUG=1,例如

externalNativeBuild {
  ndkBuild {
    arguments "NDK_DEBUG:=1"
  }
}

我已在我的 Android 清单文档中设置了 android:debuggable="true" 属性。

我已设置构建类型并将 debuggable 切换为 true 和 false

buildTypes { 
    release {
        debuggable true
        ...
    }
    debug {
        debuggable true
        ...
    }
}

我不知道我还能做什么。断言仍然未定义。我必须#define assert ; 一个空语句才能编译。我想以正确的方式去做。

【问题讨论】:

  • 你在使用ndk-r18b吗?

标签: android gradle android-ndk android-gradle-plugin


【解决方案1】:

我也在使用 CMake 并且能够使用断言。

我建议您尝试从 android-studio 'File->new project->Choose your project(向下滚动并选择 Native C++)->Next->Next-Finish' 创建新项目。这将创建带有本机组件的 android 应用程序。修改native组件的.cpp文件使用assert(include assert.h),看看是否有效。

还要检查这篇文章是否能帮助您解决问题。 https://stackoverflow.com/a/9144080/4181904

【讨论】:

  • 我正在使用 cmake
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-06
  • 1970-01-01
  • 2017-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多