0

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.

LaChen
  • 3
  • 2

2 Answers2

1

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.)

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
0

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.

LaChen
  • 3
  • 2
  • This is the correct way to define class static member, not only in NDK. See https://stackoverflow.com/a/9219987/192373. The header-only form is allowed if you set `-std=c++11`. – Alex Cohn Nov 19 '17 at 22:39