5

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
vgonisanz
  • 11,831
  • 13
  • 78
  • 130

2 Answers2

7

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)
PeterT
  • 7,981
  • 1
  • 26
  • 34
7

Indeed, a CPP macro wont be expanded in the middle of an identifier. Try with

 #define MAIN_ACTIVITY_PREFIX(func) Java_org_myproject_marker_MainActivity##func

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) {
    ...
}
Martin Geisler
  • 72,968
  • 25
  • 171
  • 229