I'm trying to compile the nvfile library from http://developer.nvidia.com/tegra-resources, in the android ndk sample, libs folder. Anyway, as I don't really need the entire suite of libraries, I pulled out the one that I needed, with what appeared to be it's dependencies. Here is the Android.mk file for compiling them.
include $(CLEAR_VARS)
LOCAL_MODULE := nvthread
LOCAL_CFLAGS := -Wall -g
LOCAL_LDFLAGS := -Wl,-Map,xxx.map
LOCAL_SRC_FILES := nv/nv_thread/nv_thread.c
LOCAL_C_INCLUDES := nv
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := nvfile
LOCAL_CFLAGS := -Wall -g
LOCAL_LDFLAGS := -Wl,-Map,xxx.map
LOCAL_SRC_FILES := nv/nv_file/nv_file.c
LOCAL_C_INCLUDES := nv
LOCAL_STATIC_LIBRARIES := nvthread nvapkfile
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := nvapkfile
LOCAL_CFLAGS := -Wall -g
LOCAL_LDFLAGS := -Wl,-Map,xxx.map
LOCAL_SRC_FILES := nv/nv_apk_file/nv_apk_file.c
LOCAL_C_INCLUDES := nv
LOCAL_STATIC_LIBRARIES := nvthread
include $(BUILD_STATIC_LIBRARY)
The nvapkfile library seems to be able to link just fine with nvthread, but the nvfile library doesn't seem to want to link to the nvapkfile library at all. The include files in the source code are working properly, it's just that whenever I try to compile it, I get an undefined reference. Here is a sample of output:
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFInit':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:49: undefined reference to `NvAPKInit'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFOpen':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:77: undefined reference to `NvAPKOpen'
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:82: undefined reference to `NvAPKOpen'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFClose':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:97: undefined reference to `NvAPKClose'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFGetc':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:118: undefined reference to `NvAPKGetc'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFGets':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:133: undefined reference to `NvAPKGets'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFSize':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:148: undefined reference to `NvAPKSize'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFSeek':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:171: undefined reference to `NvAPKSeek'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFTell':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:186: undefined reference to `NvAPKTell'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFRead':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:201: undefined reference to `NvAPKRead'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFEOF':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:216: undefined reference to `NvAPKEOF'
I haven't modified the actual c or h files at all. But for reference, is here a piece of the relative C file in question:
#include "nv_file.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef ANDROID
#include "../nv_apk_file/nv_apk_file.h"
#define SUPPORT_APK 1
#include <unistd.h>
#endif
//...
void NvFInit()
{
#ifdef SUPPORT_APK
NvAPKInit();
#endif
}
This is lines 22-32 and 46-51 of nv_file.c
As you can see, the header is getting included, but it's not linking. Does anyone have any idea what I'm missing here? Thank you.
Overview. The Android.mk file resides in a subdirectory of your project's jni/ directory, and describes your sources and shared libraries to the build system. It is really a tiny GNU makefile fragment that the build system parses once or more.
libc++ LLVM's libc++ is the C++ standard library that has been used by the Android OS since Lollipop, and as of NDK r18 is the only STL available in the NDK. Note: For full details of the expected level of C++ library support for any given version, see the C++14 Status, C++17 Status, and C++20 Status pages.
LOCAL_CFLAGS is applied to the current module, and is undefined after an include $(CLEAR_VARS) . APP_CFLAGS is applied to all modules.
Ugg..it appears I just had it in the wrong order. Turning this line (in the nvfile module):
LOCAL_STATIC_LIBRARIES := nvthread nvapkfile
to
LOCAL_STATIC_LIBRARIES := nvapkfile nvthread
made it compile just fine. Can anyone confirm that the order you list libraries in LOCAL_STATIC_LIBRARIES can be important? Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With