sbuslovsky
sbuslovsky

Reputation: 71

JNI, C++ and its standard library

I'm using some C++ code through JNI in Java. The C++ code uses some functions from libstdc++ and libz. The C++ part is linked into a shared library and than that built library is used on different environments(linux-based).

My concern is the libstdc++ and libz versions differences. If I built that JNI library on environment A and than it went to environments B and C which might have other libstdc++ and libz versions - will it fail? And does that mean I need to link those libraries into my JNI shared library statically?

P.S. The first test of 2 slightly different environments succeeded, but still I don't feel safe here.

Upvotes: 0

Views: 415

Answers (1)

Eugene
Eugene

Reputation: 9474

This is no different from non-JNI usage of the C++. Generally, library provider strive to ensure backward compatibility - so in most cases your concern is not to stumble upon a version that is too old.

There are several common options:

  1. Rely on packaging to ensure proper version of your dependency (e.g. if you package into RPM/DEB packages on Linux you set requirement in package metadata). For Mac you usually target specific OS version for standard library and bundle non-standard library (libz) with your installer. I don't think you can expect libstdc++ on Windows by default, without Cigwin and likes.
  2. Link statically.
  3. Package shared libraries with your application.

Upvotes: 2

Related Questions