静态库Android中的undefined refrence函数

时间:2015-05-15 19:13:02

标签: android c android-ndk

我获得了一个包含.a和头文件的库。 当我没有函数调用时,一切都很好,但是当我调用函数时,它说函数是未定义的。我不确定这是否与我的设置有关,因为这是我使用NDK的第一个项目,或者是头文件的问题。

ERROR

Error:(9) undefined reference to `staticLibraryFunction'

Android.mk

LOCAL_PATH := $(call my-dir)

# static library info
include $(CLEAR_VARS)
LOCAL_MODULE := A
LOCAL_SRC_FILES := my-library.a
include $(PREBUILT_STATIC_LIBRARY)

# wrapper info
include $(CLEAR_VARS)
LOCAL_MODULE    := wrapper
LOCAL_SRC_FILES := wrapper.c
LOCAL_STATIC_LIBRARIES := A
include $(BUILD_SHARED_LIBRARY)

Wrapper.c

#include <string.h>
#include <jni.h>
#include "header-for-static.h"

jstring
Java_com_rappiddev_cortexscan_MainActivity_getStringFromNative(JNIEnv *env,
                                                 jobject thiz)
{
    int handle = staticLibraryFunction();
    char temp[4] = "test";
    char str[15];
    int test = strcmp("hi", "hello");
    //sprintf(str, "%d", handle);
    return (*env)->NewStringUTF(env, temp);
}

MainActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String x = getStringFromNative();
        Log.d("test", x);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public native String getStringFromNative();

    static {
        System.loadLibrary("wrapper");
    }
}

调用staticLibraryFunction()时会发生错误。 非常感谢任何帮助。

0 个答案:

没有答案