I'm using Eclipse + Qualcomm libraries (in cpp) + Android SDK on Ubuntu. My application runs fine. If I change some code in the qualcomm libraries, it compiles and works correctly.
The problem is: I have changed the name of the project, and I have to change some code in cpp (The name of the function), if I don't do it, I get a Java.lang.UNSATISFIEDLINKERROR
.
That's because all the functions have the name as the Android package like this:
Java_org_myproject_marker_MainActivity_onQCARInitializedNative(JNIEnv *, jobject)
Then I define a macro like this:
#define MAIN_ACTIVITY_PREFIX org_myproject_marker_MainActivity
#define VISUALIZER_PREFIX org_myproject_marker_Visualizer
And I change all the correct functions by:
Java_MAIN_ACTIVITY_PREFIX_onQCARInitializedNative(JNIEnv *, jobject)
but I am still getting the Java.lang.UNSATISFIEDLINKERROR
exception.
It works if I do it without the #define
macro (and write all the lines), but I want to save the cpp code with a top define that changes everything automatically if I need to use it in other projects.
I have read this tutorial. Can't I replace a text inside another text or something like that?
A macro is a piece of code in a program that is replaced by the value of the macro. Macro is defined by #define directive. Whenever a macro name is encountered by the compiler, it replaces the name with the definition of the macro.
The preprocessor supports text macro replacement. Function-like text macro replacement is also supported. The #define directives define the identifier as macro, that is instruct the compiler to replace all successive occurrences of identifier with replacement-list, which can be optionally additionally processed.
Also note that macro replacement commonly results in multiply evaluation of the arguments, whereas a function call does not, and hence macros replicate side effects contain inside the argument, such as ++ and other function calls. Function calls also convert arguments to parameter types, whereas macros do not.
Indeed, a CPP macro wont be expanded in the middle of an identifier. Try with That gives you a macro that will prepend Java_org_myproject_marker_MainActivity to the function name you pass it. Use it as: MAIN_ACTIVITY_PREFIX (_onQCARInitializedNative) (JNIEnv *, jobject) { ...
you are looking for string concatenation, like this:
#define MAIN_ACTIVITY_PREFIX(n) Java_org_myproject_marker_MainActivity##n
and then use it like this:
MAIN_ACTIVITY_PREFIX(_onQCARInitializedNative)(JNIEnv *, jobject)
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