LaChen
LaChen

Reputation: 3

UnsatisfiedLinkError about Static Member initialized in class in ndk r15

I encounter a problem about UnsatisfiedLinkError.

My code is :

class ClassA
{
public:
  static const int MY_ENUM_1 = 0;
};

I use Android Studio build my code to .a.

And then I write .so for link the interface of my lib via JNI.

I build the project successfully. But it occur an error about this while run-time,

 java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN12LaChenEngine14GraphicsSystem22VertexBufferAccessList12DYNAMIC_DRAWE

LaChenEngine is the namespace.

GraphicsSystem is the namespace in LaChenEngine.

VertexBufferAccessList is my class for declaring all enum.

DYNAMIC_DRAW is one of enum in class VertexBufferAccessList.

Is this problem about version in ndk?

By the way, I develop my library on Windows Platform.

Upvotes: 0

Views: 140

Answers (2)

LaChen
LaChen

Reputation: 3

I test many version of ndk, it still happen again and angin.

So I decide to change the code like this :

//.h
class ClassA
{
public:
   static const int MY_ENUM_1;
};
//.cpp
const int ClassA::MY_ENUM_1 = 0;

And then, it work.

Thanks for all helps.

Upvotes: 0

18446744073709551615
18446744073709551615

Reputation: 16872

One possible cause is that one project defines a extern "C" function, and the other assumes that it is a C++ function. More info: https://stackoverflow.com/a/1041880/755804

Another guess: check if that function is there in your .so, and if not, find out where it is.

In general, how I would approach such linkage problem is: I would start with a hello-jni application, adding one feature at a time (another library, C++ functions, C++ functions in name spaces, etc.)

Upvotes: 1

Related Questions