android c 11 编译,c++11 - 无法使用适用于Android的CMake GUI启用C ++ 11的ChaiScript编译 - 堆栈内存溢出...

我本人为此问题发布了该解决方案。 (当我使用eclipse + jni而不是CMake GUI编译代码时,它不能很好地解决所提出的问题。但这可能会对某人有所帮助。)

源代码已成功编译,使用Eclipse IDE + Android Project + JNI方法(Android NDK + Android.mk + Application.mk)构建。 通过引用一些stackoverflow QA,下面给出了Android.mk和Application.mk脚本。 在脚本内部的注释中,给出了使用标志的原因。 这些注释对于理解脚本很有用。

Android.mk

LOCAL_PATH := $(call my-dir)

#Build Script to build ChaiScript library

include $(CLEAR_VARS)

#Used the below flag for (error: undefined reference to '__atomic_fetch_add_4')

LOCAL_LDLIBS += -latomic

# Here we give our module name and source file(s)

LOCAL_MODULE := chaiscript

#ChaiScript header files

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include_CS

#ChaiScript source files

LOCAL_SRC_FILES := src_CS/chaiscript_stdlib.cpp src_CS/main.cpp src_CS/stl_extra.cpp src_CS/test_module.cpp

#CPP files in the extension

LOCAL_CPP_EXTENSION := .cxx .cpp .cc .hpp

include $(BUILD_SHARED_LIBRARY)

#Build Script to build library caller code

#LOCAL_PATH := $(call my-dir) #won't get cleared by clear_vars

include $(CLEAR_VARS) #clearing the variables defined for chaiscript build

LOCAL_MODULE := test_chaiscript

LOCAL_SRC_FILES := libchaiscript.so #can be 'chaiscript' alone

#ChaiScript Library headerfiles

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include_CS

#Caller code header files

LOCAL_C_INCLUDES := $(LOCAL_PATH)/header_own

#Caller code source files

LOCAL_SRC_FILES := src_own/NativeFunction.cpp src_own/clsArithmeticParser.cpp

include $(BUILD_SHARED_LIBRARY)

Application.mk

#APP_STL := stlport_static

#Build the library by enabling C++11

APP_STL:=c++_static

APP_LDLIBS += -llog

#Used the below flag for

#(Error: '...' handler must be the last handler for its try block [-fpermissive]

# } catch (const std::out_of_range &) {)

APP_CPPFLAGS += -fexceptions

#Used the below flag for (Error: 'dynamic_cast' not permitted with -fno-rtti)

APP_CPPFLAGS += -frtti

#Architecture to support armeabi-v7a & x86

APP_ABI := armeabi-v7a x86

#Android platform

APP_PLATFORM := android-21

由于我的android ndk版本不支持thread_local存储类,因此我需要将宏“ CHAISCRIPT_HAS_THREAD_LOCAL”取消定义为文件chaiscript_threading.hpp

#undef CHAISCRIPT_HAS_THREAD_LOCAL (you can understand if you refer the source code)

ndk-build输出:

ndk-build

Android NDK: WARNING: APP_PLATFORM android-21 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml

[armeabi-v7a] Compile++ thumb: chaiscript <= chaiscript_stdlib.cpp

[armeabi-v7a] Compile++ thumb: chaiscript <= main.cpp

[armeabi-v7a] Compile++ thumb: chaiscript <= stl_extra.cpp

[armeabi-v7a] Compile++ thumb: chaiscript <= test_module.cpp

[armeabi-v7a] SharedLibrary : libchaiscript.so

[armeabi-v7a] Install : libchaiscript.so => libs/armeabi-v7a/libchaiscript.so

代码用法:

#include "header_own/NativeFunction.h"

#include "include_CS/chaiscript/chaiscript.hpp"

#include "include_CS/chaiscript/chaiscript_stdlib.hpp"

std::string str;

std::string helloWorld(const std::string &t_name) {

str = "Hello " + t_name + "!";

return "Hello " + t_name + "!";

}

JNIEXPORT jstring JNICALL Java_com_example_androidxmldesign_1exercise01_clsNativeFunctionWrapper_invokeNativeFunction(

JNIEnv *env, jobject obj) {

chaiscript::ChaiScript chai(chaiscript::Std_Lib::library());

chai.add(chaiscript::fun(&helloWorld), "helloWorld");

chai.eval(R"(puts(helloWorld("Bob"));)");

//below string return value will be appended to a textview

//existing vlaue

return env->NewStringUTF(str.c_str());

}

屏幕截图: c119e42f87f91ae6b9c2be920115a4b8.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值