I am building a C++ library for android. I have X.so shared library which ends up in the android app and it's accessed through JNI. I also have a Y.a static library which has few generic functions that is used by X.so. Y.a also has some JNI interface functions as well that should be accessible by the android app. Currently the problem I'm having is that, after building Y.a, I can see all the symbols I need to be exported. But after linking that to X.so, linker discards all the JNI interface functions because they are not used internally. I tried the following 2 options without any luck,
1.
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL myImportantFunction(JNIEnv*, jclass);
.
.
.
void* volatile tmp = (void*)&myImportantFunction;
#ifdef __cplusplus
}
#endif
2.
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void __attribute__((used)) JNICALL myImportantFunction(JNIEnv*, jclass);
.
.
.
#ifdef __cplusplus
}
#endif
If there are any clang attributes or hacks which can force the linker not to discard specific functions I need (when I'm building Y.a) it would be ideal. Thank you all for any help in this regards.