NDK共享库“未定义引用”

时间:2017-04-02 11:09:46

标签: c++ eclipse android-ndk shared-libraries

我创建了非常简单的共享库并使用NDK构建它以便我想在原生的android项目中使用它,这个库有一个名为shaderprogram的类及其头文件,我用这个mk文件构建它

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := NativeGLLib
LOCAL_SRC_FILES := NativeGLLib.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/includes
APP_ABI:=all

LOCAL_CPP_FEATURES += exceptions
LOCAL_CPPFLAGS += -fexceptions

LOCAL_LDLIBS := -lGLESv2

include $(BUILD_SHARED_LIBRARY)

然后我将includes文件夹手动复制到本机项目jni文件夹,并将libs内容从库构建复制到jni / lib,它包含设备arm64-v8a,armeabi,armeabi-v7a等的版本。 我有一个名为game.cpp的类,我实现了共享库

#include "includes/game.h"

#include <GLES2/gl2.h>

#include "includes/shaderprogram.h"

using namespace std;
using namespace GameEngine::Core;

ShaderProgram shaderP;
int programId;

void on_surface_created() {
    glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
    glEnable(GL_DEPTH_TEST);
    programId = shaderP.getProgramId();
}

void on_surface_changed() {
    // No-op
}

void on_draw_frame() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

这是项目的android.mk文件

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := mylib
LOCAL_SRC_FILES := lib/$(APP_ABI)/libNativeGLLib.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/includes

include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := game
LOCAL_SRC_FILES := glnative.cpp game.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/includes
LOCAL_SHARED_LIBRARIES := mylib

LOCAL_CPP_FEATURES += exceptions
LOCAL_CPPFLAGS += -fexceptions

LOCAL_LDLIBS := -lGLESv2

include $(BUILD_SHARED_LIBRARY)

当我尝试构建项目时,我收到此错误

[arm64-v8a] SharedLibrary  : libgame.so
 ./obj/local/arm64-v8a/libNativeGLLib.so: error adding symbols: File in wrong format
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

make:*** [obj / local / arm64-v8a / libgame.so]错误1

0 个答案:

没有答案