Ask Your Question
0

Java JNI “symbol lookup error” from custom native extension using OpenCV C++

asked 2018-01-05 08:13:32 -0600

jimfcarroll gravatar image

updated 2018-01-06 16:41:30 -0600

I'm augmenting the Java wrapper for OpenCV with some of my own code. In a nutshell here is my build process:

  1. On Ubuntu 16.04 I'm building OpenCV (3.4.0) Java wrapper statically linked so that all of the rest of the OpenCV libraries is in the JNI library.
  2. I have my own JNI library built as a separate shared library with code against the C++ implementation of OpenCV
  3. I explicitly System.load() both shared libraries into my java code.

I have much of it working except one method that seems to trigger the following error

java: symbol lookup error: [path to my library].so: undefined symbol: _ZN2cv6String8allocateEm

This is the cv::String::allocate method from stl.cpp. Using nm on the OpenCV library I can see the symbol is defined as local (indicated by the lower case 't'):

0000000000442990 t _ZN2cv6String8allocateEm

When I run make with VERBOSE=1 I can see that -fvisibility=hidden is being passed to the compiler for stl.cpp.

If this is intentional can someone please let me know what I'm supposed to do? Obviously this will work if I build my code directly into the OpenCV shared library but I'd prefer not to do that. I'm not explicitly calling that method so it's being called indirectly from what I am calling (which is imshow).

__EDIT:__ It doesn't link on Windows at all. On Linux it leaves the symbols and "undefined" and my code path doesn't require it but on Windows it wont link. It seems to me that this means anyone creating a shared library that uses OpenCv wont be able to link on Windows ore run on Linux.

Any suggestions?

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2018-01-07 08:31:46 -0600

jimfcarroll gravatar image

updated 2018-01-07 08:32:05 -0600

This is currently intentionally the case. The controlling variable is CVAPI_EXPORTS set by CMake. If someone is interested in the solution, follow the Issue here: https://github.com/opencv/opencv/issu...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-01-05 08:13:32 -0600

Seen: 1,839 times

Last updated: Jan 07 '18