0

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

Marmoy
  • 8,009
  • 7
  • 46
  • 74
N-JOY
  • 10,344
  • 7
  • 51
  • 69
  • can you provide the output of `file libUtils.a`? – plaisthos Nov 29 '11 at 13:54
  • sorry but i cant get you? output? – N-JOY Nov 29 '11 at 13:55
  • Was your library compiled for android? If the library contains code for another type of processor (instruction-set), it won't work! – bert-jan Nov 29 '11 at 13:55
  • @bert-jan library was compiled with xcode on mac os. and working fine for iphone – N-JOY Nov 29 '11 at 13:58
  • You need to compile it for Android using Cygwin for example, have you done that? – Donal Rafferty Nov 29 '11 at 14:01
  • @donalRafferty ya i tried that but i got some compilation errors.(as it couldn.t find few includes from cygwin on windows and from terminal on mac as well). thats why i decided to go with this compiled version of library. – N-JOY Nov 29 '11 at 14:06
  • Which version of the NDK are you using? Google Crystax NDK to see if that version of the NDK has the includes you require. – Donal Rafferty Nov 29 '11 at 15:50

1 Answers1

5

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.

plaisthos
  • 6,255
  • 6
  • 35
  • 63