简体   繁体   中英

Error in linking C++ static library with android ndk(Error: file format not recognized)

I am trying to include static cpp library in android. This library is already compiled( on mac os ) and i have its include files.

Here is my Android.mk file

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)

and here is Application.mk file

APP_STL := stlport_static
APP_CPPFLAGS = -fexceptions  

but whenever it try to compile it using NDK i get the error

(Path of file)/libUtils.a: file not recognized: File format not recognized collect2: ld returned 1 exit status

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.

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM