using 3rd party libraries in NDK

325 views
Skip to first unread message

Nathan Yadlin

unread,
Mar 11, 2010, 3:41:57 AM3/11/10
to android-ndk
Hello!

I'm trying to use functions that are stored in a 3rd party .a or .so
file.
Not using the JNI, I wish to call these functions within the Native
code.

I've added them to my Android.mk file, but it always returns:
undefined reference to 'FunctionName'.

How do I make the code aware of the functions that are stored in the
library?
is it simply by linkage or am I missing Something?

my Android.mk looks like this:

------------------------------------------------------------------------------------------------------------------------------------
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# the purpose of this sample is to demonstrate how one can
# generate two distinct shared libraries and have them both
# uploaded in

LOCAL_PATH:= $(call my-dir)

# first lib, which will be built statically
#
include $(CLEAR_VARS)

LOCAL_MODULE := libtwolib-first
LOCAL_LDLIBS += $(LOCAL_PATH)/libs/mylib.a mylib
LOCAL_SRC_FILES := first.c

include $(BUILD_STATIC_LIBRARY)

# second lib, which will depend on and include the first one
#
include $(CLEAR_VARS)

LOCAL_MODULE := libtwolib-second
LOCAL_SRC_FILES := second.c

LOCAL_STATIC_LIBRARIES := libtwolib-first

include $(BUILD_SHARED_LIBRARY)

------------------------------------------------------------------------------------------------------------------------------------

Thanks is advance,

Nathan

Michael Maloney

unread,
Mar 25, 2010, 1:26:30 PM3/25/10
to android-ndk
I'm also in need of linking to a 3rd party library.

I'm assuming that the precompiled static libraries are useless, since
they don't conform to the ABI. But then, how do I compile these
libraries from source? It seems to require a fairly deep understanding
of the NDK toolchain. Unfortunately, I don't know 'make' well enough
to figure out how NDK is building these binaries.

I'd rather not bundle the 3rd party lib source code in with my Android
project files. How difficult would it be to convert the 3rd party's
Makefile to use the NDK build tools?

David Turner

unread,
Mar 25, 2010, 2:23:02 PM3/25/10
to andro...@googlegroups.com
On Thu, Mar 25, 2010 at 10:26 AM, Michael Maloney <tact...@gmail.com> wrote:
I'm also in need of linking to a 3rd party library.

I'm assuming that the precompiled static libraries are useless, since
they don't conform to the ABI. But then, how do I compile these
libraries from source? It seems to require a fairly deep understanding
of the NDK toolchain. Unfortunately, I don't know 'make' well enough
to figure out how NDK is building these binaries.

Read the documentation, write a small Android.mk file, it's not that hard and the NDK build scripts will handle the really hard details for you.
 
I'd rather not bundle the 3rd party lib source code in with my Android
project files. How difficult would it be to convert the 3rd party's
Makefile to use the NDK build tools?

Depends on the original Makefile, someone will have to do the work and see.
 
--
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.


Michael Maloney

unread,
Mar 26, 2010, 10:13:40 AM3/26/10
to android-ndk
On Mar 25, 1:23 pm, David Turner <di...@android.com> wrote:

> On Thu, Mar 25, 2010 at 10:26 AM, Michael Maloney <tactic...@gmail.com>wrote:
>
> > I'm also in need of linking to a 3rd party library.
>
> > I'm assuming that the precompiled static libraries are useless, since
> > they don't conform to the ABI. But then, how do I compile these
> > libraries from source? It seems to require a fairly deep understanding
> > of the NDK toolchain. Unfortunately, I don't know 'make' well enough
> > to figure out how NDK is building these binaries.
>
> > Read the documentation, write a small Android.mk file, it's not that hard
>
> and the NDK build scripts will handle the really hard details for you.
>
> > I'd rather not bundle the 3rd party lib source code in with my Android
> > project files. How difficult would it be to convert the 3rd party's
> > Makefile to use the NDK build tools?
>
> > Depends on the original Makefile, someone will have to do the work and see.
> > --
> > 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%2Bunsu...@googlegroups.com>

> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-ndk?hl=en.

I managed to get it set up. Using Application.mk's APP_BUILD_SCRIPT
variable allowed me to organize everything the way I want.

I have one small issue I had left. Right now, I have to specify every
single .c in the Android.mk's LOCAL_SRC_FILES variable. I used some
vim macros to format everything for me, and it compiles, and it runs,
but obviously, this is far from ideal. How can I set more easily set
LOCAL_SRC_FILES to the list of all .c files in a directory?

a2ronus

unread,
Apr 9, 2010, 9:10:51 AM4/9/10
to android-ndk
Check http://android.git.kernel.org/?p=platform/build.git;a=blob;f=core/definitions.mk.

Search for example for: "all-subdir-c-files".


On 26 mrt, 16:13, Michael Maloney <tactic...@gmail.com> wrote:
> On Mar 25, 1:23 pm, David Turner <di...@android.com> wrote:
>
>
>
>
>
> > On Thu, Mar 25, 2010 at 10:26 AM, Michael Maloney <tactic...@gmail.com>wrote:
>
> > > I'm also in need of linking to a 3rd party library.
>
> > > I'm assuming that the precompiled static libraries are useless, since
> > > they don't conform to the ABI. But then, how do I compile these
> > > libraries from source? It seems to require a fairly deep understanding
> > > of the NDK toolchain. Unfortunately, I don't know 'make' well enough
> > > to figure out how NDK is building these binaries.
>
> > > Read the documentation, write a small Android.mk file, it's not that hard
>
> > and the NDK build scripts will handle the really hard details for you.
>
> > > I'd rather not bundle the 3rd party lib source code in with my Android
> > > project files. How difficult would it be to convert the 3rd party's
> > > Makefile to use the NDK build tools?
>
> > > Depends on the original Makefile, someone will have to do the work and see.
> > > --
> > > 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>

David Turner

unread,
Apr 9, 2010, 1:02:51 PM4/9/10
to andro...@googlegroups.com
MY_FILES := $(wildcard $(LOCAL_PATH)/foo/*.c)

LOCAL_SRC_FILES := $(MY_FILES:$(LOCAL_PATH)/%=%)

The first line will get all C files under $(LOCAL_PATH)/foo
The second line will get rid of the $(LOCAL_PATH) prefix in the list, because the build scripts assume that all files listed in LOCAL_SRC_FILES have their path relative to $(LOCAL_PATH)

Hope this helps.

To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages