使用Android NDK链接C ++静态库错误(错误:文件格式无法识别) [英] Error in linking C++ static library with android ndk(Error: file format not recognized)
问题描述
我想包括在Android的静态CPP库。这个库已经编译(在Mac OS )和我有它包含文件。
I am trying to include static cpp library in android. This library is already compiled(on mac os) and i have its include files.
下面是我的 Android.mk
文件
LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_MODULE:= utils
LOCAL_SRC_FILES:= libUtils.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/utils
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := sample
LOCAL_SRC_FILES := sample_cpp.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_STATIC_LIBRARIES := utils
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
和这里是 Application.mk
文件
APP_STL := stlport_static
APP_CPPFLAGS = -fexceptions
不过一旦尝试使用NDK我得到的错误编译
but whenever it try to compile it using NDK i get the error
(文件的路径)/libUtils.a:文件无法识别:文件格式无法识别
collect2:劳工处返回1退出状态
推荐答案
从意见等这听起来像你想使用图书馆的非ARM版。你应该建立一个与NDK库。该文件对如何做到这一点,甚至文档。
From the comments and so on it sounds like you trying to use a non arm version of the library. You should build the library with the ndk. The documentation has even documentation on how to do that.
例如建筑sigc ++也能像(从我的一个项目,其中sigc ++驻留在sigc ++子目录)
For example building sigc++ could be like (from a project of mine, where sigc++ resides in the sigc++ subdirectory)
# SIGC++ Library built as static library
LOCAL_MODULE := sigc
LOCAL_PATH = $(CURRENT_DIR)
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := sigc++/signal.cc sigc++/signal_base.cc sigc++/trackable.cc
LOCAL_SRC_FILES += sigc++/functors/slot_base.cc sigc++/adaptors/lambda/lambda.cc
LOCAL_SRC_FILES += sigc++/connection.cc sigc++/functors/slot.cc
LOCAL_C_INCLUDES := sigc++
include $(BUILD_STATIC_LIBRARY)
但你真的应该阅读编译链接是如何工作。恐怕建设的Android NDK具有更低水平比使用X code或MSVC。
But you should really read how the compiling linking works. I am afraid building for android with ndk is more low level than using Xcode or Msvc.
这篇关于使用Android NDK链接C ++静态库错误(错误:文件格式无法识别)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!