Loading static library (.lib)

1,193 views
Skip to first unread message

Ben

unread,
Jul 29, 2010, 10:24:32 AM7/29/10
to android-ndk
Hi!

First of all I want to apologize if I sound quite new to the whole
topic, but I am.
I haven't found a clear tutorial or explanation of how I can load a
static library (I am working under windows so it comes in the shape of
a .lib file) with the ndk framework so I can use it in my c++ code,
connected via JNI to my Android app.

I have placed my library vbase_d.lib (which was created earlier from
within Visual Studio) in the jni/ folder of my project. My android.mk
looks like this:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := frameworkCaller
LOCAL_SRC_FILES := frameworkCaller.cpp

LOCAL_LDLIBS := -lvbase_d.lib

include $(BUILD_SHARED_LIBRARY)


If I call ndk_build I get the following error:

$ ndk-build
SharedLibrary : libframeworkCaller.so
/cygdrive/c/Dev/android-ndk-r4b/build/prebuilt/windows/arm-eabi-4.4.0/
bin/../lib
/gcc/arm-eabi/4.4.0/../../../../arm-eabi/bin/ld: cannot find -
lvbase_d.lib
collect2: ld returned 1 exit status
make: *** [/cygdrive/c/Dev/workspace/JNITest/obj/local/armeabi/
libframeworkCalle
r.so] Error 1

Obviously the library is not found, so can anyone tell me where I
should put the .lib file or if loading an external .lib file is
complete garbage anyway?

Thanks for your answers in advance

Pedro Lamarão

unread,
Jul 29, 2010, 1:14:23 PM7/29/10
to android-ndk
Ben wrote:

> LOCAL_LDLIBS := -lvbase_d.lib

Ben wrote:

> LOCAL_LDLIBS := -lvbase_d.lib

To include a static library in the link:

LOCAL_LDLIBS := /path/to/liblvbase.lib

--
P.

Christian Linne

unread,
Jul 29, 2010, 1:32:52 PM7/29/10
to andro...@googlegroups.com
You should note that using a windows-library (in general) will not work - it has to be rebuilt (.a - files are the equivalent to .libs, approximately).

2010/7/29 Pedro Lamarão <pedro....@gmail.com>

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.




--
_________
Regards,

christian.l

charles

unread,
Aug 2, 2010, 2:26:47 AM8/2/10
to android-ndk
Hi,

You need to first be compiling your static library against bionic libc
(the C library used by Android). Since Android runs on Linux, the
appropriate file extension for a static library will be ".a". Windows
static libraries (".lib") will not work.

There is an NDK macro $(BUILD_STATIC_LIBRARY), if you are new to this
then I suggest doing it this way. Here is an example of what your
Android.mk file should include:

#------------------------------------
# Android.mk
#------------------------------------

LOCAL_PATH := $(call mydir)

# First, build your static library.

include $(CLEAR_VARS)

LOCAL_MODULE := mylib-static
LOCAL_SRC_FILES := my_c_file.c

include $(BUILD_STATIC_LIBRARY)

# Next, build your shared library which includes the static library.

include $(CLEAR_VARS)

LOCAL_MODULE := mylib-shared
LOCAL_SRC_FILES := my_other_c_file.c

LOCAL_STATIC_LIBRARIES := libmylib-static

# Include this next line if you want to write to the system log from
your native code.
LOCAL_LDLIBS := -llog

include $(BUILD_SHARED_LIBRARY)

#-------------------------------
# EOF
#-------------------------------

If there is some compelling reason to build your static library
outside the NDK, I suppose to compile your static library against
Bionic libc by hand (or using a GNU Makefile) and then include this in
your app by building it into a shared library created by your
Android.mk file...

Read the NDK documentation (ANDROID-MK.txt explains the
*_STATIC_LIBRARIES macros) and check out the .mk scripts that are
actually being used when `ndk-build` is invoked.

Good luck!

- Charles

On Jul 29, 12:32 pm, Christian Linne <christian.li...@googlemail.com>
wrote:
> You should note that using a windows-library (in general) will not work - it
> has to be rebuilt (.a - files are the equivalent to .libs, approximately).
>
> 2010/7/29 Pedro Lamarão <pedro.lama...@gmail.com>
>
>
>
>
>
> > Ben wrote:
>
> > > LOCAL_LDLIBS := -lvbase_d.lib
>
> > Ben wrote:
>
> > > LOCAL_LDLIBS := -lvbase_d.lib
>
> > To include a static library in the link:
>
> > LOCAL_LDLIBS := /path/to/liblvbase.lib
>
> > --
> >  P.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>
> > .
Reply all
Reply to author
Forward
0 new messages