简体   繁体   中英

compiling non local files using NDK, Linker error

Many related questions have been asked regarding NDK linker errors, but I couldnt clearly found a solution to my situation. I am trying to extend a sample NDK applicaiton, by adding 4 more local files of my own. I am including them in the Android.mk file, and including the .h files appropriately. Here is my Android.mk file.

include $(BUILD_SHARED_LIBRARY)

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := libgl2jni
LOCAL_CFLAGS    := -Werror
LOCAL_SRC_FILES := gl_code.cpp \
                  sglBandwidthBench.c \
                  sglBandwidth.c \
                  common.c \
                  timer.c

LOCAL_LDLIBS    := -llog -lGLESv3 -lEGL

include $(BUILD_SHARED_LIBRARY)

and the .h files inclusion has been proper. but the compilation gives me undefined reference to function x. I added the files sglBandwidthBench.c sglBandwidth.c common.c timer.c, none of them contain a main function, and the only link is through referecing one of those functions in gl_code.cpp.

how can I link these files together successfully? I couldnt think of any way of specifying it. Any help would be much appreciated.

As you may know, link errors on undefined references are due to one or more method's implemetation not being found by the build system inside the prebuit libraries you provided. So, bottom line, you are probably missing the shared library which contains the implementation for function x .

My advice would be to double-check if you actually have libGLESv3.so under any of your <ndk>\\platforms\\<android-api-level>\\arch-arm\\usr\\lib directory. Alternatively, check <ndk>\\docs\\STABLE-APIS.html to see if all the libraries you're using are listed there. If one of them is not, you will either need to upgrade your NDK version or to manually add the missing library to your source code (for that, read section PREBUILT_SHARED_LIBRARY from <ndk>\\docs\\ANDROID-MK.html ).

Hope that this helps!

EDIT: Hi Sai, from what I just learned from your comments, you are trying to call a method implemented in a .c file from inside a .cpp one. So you need to enclose the contents of your gl_code.cpp with the following piece of code:

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM