我想爲Android製作APP本機代碼。本地代碼在cplusplus中。 每當我嘗試製作時,都會出現以下錯誤。啓用異常C++
H236Plus.cpp:135: error: exception handling disabled, use -fexceptions to enable
如何使用-fexceptions啓用異常處理,以及在哪裏使用它?
我想爲Android製作APP本機代碼。本地代碼在cplusplus中。 每當我嘗試製作時,都會出現以下錯誤。啓用異常C++
H236Plus.cpp:135: error: exception handling disabled, use -fexceptions to enable
如何使用-fexceptions啓用異常處理,以及在哪裏使用它?
您需要使用CrystaX的custom NDK構建。它具有完整的libstdC++,RTTI和異常支持。它通常是我知道的Android開發的最佳工具。
-fexception是一個編譯器開關。你如何使用它取決於你的編譯器設置。你使用什麼編譯器? IDE?構建工具?
使用cygwin的NDK。我所做的只是在cygwin的ndk文件夾目錄中輸入「make APP = project」。 – Gidiyo 2010-07-10 15:07:01
這個目錄應該有一個Makefile。這控制着如何編譯所有東西。這是尋找編譯器開關的地方。 – EricSchaefer 2010-07-10 18:05:45
它是** - fexception **還是** - fexceptions **? – 2017-05-23 19:05:53
這取決於您使用的是什麼運行時。如果你不使用的系統運行,並與ndk-build
正在建設中,添加任何這些你的Android.mk文件:
此外,您可以將下面的行添加到您的Application.mk文件:
在NDK文件夾
我加入CFLAGS 「-fexceptions」到的build.gradle腳本NDK部分,這樣解決了這個問題,還有更精彩的信息docs/CPLUSPLUS-SUPPORT.html
:
ndk {
...
cFlags "-fexceptions"
}
與Android Studio的最新版本,這是我的build.gradle外觀:
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles.add(file("proguard-rules.txt"))
signingConfig = $("android.signingConfigs.release")
}
}
defaultConfig {
applicationId "my.android.app"
minSdkVersion.apiLevel 16
targetSdkVersion.apiLevel 23
versionCode 29
versionName "my.latest.version"
}
ndk {
moduleName "jni-utils"
ldLibs.add("log")
cppFlags.add("-std=c++11")
cppFlags.add("-fexceptions")
stl "gnustl_static"
}
}
android.signingConfigs {
create("release") {
storeFile "C:\\Android\\Git\\MyProject\\keystore\\keystoreCommon"
storePassword "put you password here"
keyAlias "put your alias here"
keyPassword "put your password here"
}
}
}
要使用ndk-build啓用它,請在您的Android.mk中使用新的LOCAL_CPP_FEATURES變量,如下所示: LOCAL_CPP_FEATURES + =例外 – hB0 2013-11-07 20:37:12