2

我有一个用 NDK 编写的主要逻辑的 android 程序。但现在我想评估一些 python 代码作为主要逻辑的一部分。所以我尝试在 c http://docs.python.org/2/extending/embedding.html中使用这个嵌入 python

我创建了一个简单的android项目,像这样使用native.c(我所做的只是添加python头文件)

#include <Python.h>
#include <jni.h>
#include <string.h>
#include <android/log.h>
#include <pthread.h>
#define DEBUG_TAG "NDK_AndroidNDK1SampleActivity"

void Java_com_example_com_test_mytest_MainActivity_helloLog(JNIEnv * env, jobject this, jstring logThis)
{
    jboolean isCopy;
    const char * szLogThis = (*env)->GetStringUTFChars(env, logThis, &isCopy);
    __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:LC: [%s]", szLogThis);
    (*env)->ReleaseStringUTFChars(env, logThis, szLogThis);
}

这是我的 Android.mk

LOCAL_PATH := $(call my-dir)  
include $(CLEAR_VARS)  
LOCAL_LDLIBS := -llog `python2.7-config --ldflags`
LOCAL_MODULE    := ndk1  
LOCAL_SRC_FILES := native.c  
LOCAL_CFLAGS := `python2.7-config --cflags`
#LOCAL_SHARED_LIBRARIES := -lpthread
include $(BUILD_SHARED_LIBRARY) 

编译时出现以下错误(使用 Mac)

Compile thumb  : ndk1 <= native.c
arm-linux-androideabi-gcc: error: i386: No such file or directory
arm-linux-androideabi-gcc: error: x86_64: No such file or directory
arm-linux-androideabi-gcc: error: unrecognized option '-arch'
arm-linux-androideabi-gcc: error: unrecognized option '-arch'
make: *** [obj/local/armeabi/objs/ndk1/native.o] Error 1

任何人都可以帮忙吗?:D

4

1 回答 1

0

Python2.7-config 是为 64 位 i386 系统而不是 Android 构建的。它在 LOCAL_CFLAGS 字段中将错误的参数传递给编译器。要么运行一个你为在 Android 上交叉编译而构建的程序,要么自己指定值。检查谷歌的“Python-For-Android”(Py4A)如何在 NDK 应用程序中嵌入 python。

于 2013-09-18T15:21:48.170 回答