5

I am working with Android NDK r6b under cygwin (the system is updated correctly). I am modifying the hello-jni sample in order to learn working with NDK. Since i have a library written in C++ that i wish to use in the hello-jni (actually, i have created a prj called helloworld with a single .cpp file called ndkfoo.cpp) sample, i created a new Android project in Eclipse (updated for Android), added a jni directory, added a Android.mk and Application.mk files, edited them in order to compile the .cpp. At the end of the compilation, i obtain a .so file.

Now, in the helloworld Android.mk, i need to make some edits in order to tell the linker to include that library. Suppose the library file is libmylib.so, i have the following android.mk script:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := ndkfoo

LOCAL_SRC_FILES := ndkfoo.cpp

LOCAL_C_INCLUDES += $(LOCAL_PATH)/mylib

LOCAL_LDLIBS += -L$(LOCAL_PATH)/../../mylib/libs/armeabi/ -lmylib

include $(BUILD_SHARED_LIBRARY)

My directories are organized in the following way:

d:/android/android-ndk-r6b => android ndk root
d:/android/workspace/helloworld => helloworld project
d:/android/workspace/mylib => mylib project library

(therefore, the path to libmylib.so is: d:/android/workspace/mylib/libs/armeabi).

Unfortunately, this doesn't seems to work. If i remove every reference to mylib from ndkfoo.cpp, it compiles and run even on my phone. If i do not remove references to mylib, it compiles but doens't link: i obtain the following result:

D:/android/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windo ws/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/ bin/ld.exe: cannot find -lmylib

Ps. I forgot to mention that i run ndk-buld under the jni directory of the helloworld project. Pss. I have found a lot of similar questions over the internet. I have always worked with Visual C/C++ IDE, so i am really new to GCC, makefiles and so on...

durron597
  • 31,968
  • 17
  • 99
  • 158
Luke
  • 641
  • 3
  • 8
  • 14
  • 1
    Ok, found how to solve this issue. For some strange reason that i don't understand, the path specified as -L/cygdrive/d/android/workspace/mylib/libs/armeabi does not work (and this is why the use of LOCAL_PATH results in a error). Instead, using -Ld:/android/workspace/mylib/libs/armeabi or -L../../mylib/libs/armeabi does work. I suppose cygwin is the problem here... – Luke Sep 09 '11 at 18:19
  • post your comment as answer if it solves your issue – m-ric Sep 04 '12 at 18:41

1 Answers1

1

The message

D:/android/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windo ws/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/ bin/ld.exe: cannot find -lmylib

is indicating you that the linker is not finding your library, this should come from a problem in the LD_LIBS' path.

I think that my-dir macro does not include devices' unit identifier so, your LOCAL_PATH variable should miss the D: and, I think, won't work with cygwin. I'm a Linux user and I'm not 100% sure but, if you replace

LOCAL_PATH := $(call my-dir)

by

LOCAL_PATH := D:$(call my-dir)

it should work. On the other hand you can always set the relative path by setting:

LOCAL_LDLIBS += -L$../../mylib/libs/armeabi/ -lmylib
durron597
  • 31,968
  • 17
  • 99
  • 158
jcm
  • 2,568
  • 14
  • 18