Kyou.
Kyou.

Reputation: 58

Ubuntu+CMake, Cannot static-build C/C++ android-ndk programs

my friend, I've come across the following problem that gives me a headache. Can you help me to point out where the problem is?

NDK r20b

Building the environment involves three libraries

  1. C ++ 11/ STL
  2. OpenSSL 1.1.1i
  3. Boost 1.7.0

The above three libraries, through the static library link to the target-exe

A: -DANDROID_STL=c++_static is specified on the cmake command line, but make compiled android-cxx-program still requires dynamic loading libc++_shared.so file!

B: I tried to compile statically by replacing a / so and other files in the directory of NDK tool chain, but encountered either the symbol “C++/STL” could not be found, or it had no effect.

I forced cmake link libc++_static.a file, except after the built file volume increases, but for dependence still needed libc++_shared.so!

Now I don't know how to compile without relying on libc++_shared.so.

Supplement:

Because, it needs to be compiled into an independent exe executable Android C/C++ native program, which is not called through Java / JNI, and now it can not solve the problem of not relying on libc++_shared.so.

Upvotes: 1

Views: 665

Answers (1)

Mykola Khyliuk
Mykola Khyliuk

Reputation: 1423

According to NDK C++ library support:

In general, you can only use a static variant of the C++ runtime if you have one and only one shared library in your application.

Note: This rule applies to both your code and your third party dependencies.

So, it means that you need to compile all of your stuff with "-DANDROID_STL=c++_shared".

Also here is an example of what can happen when using different STL libraries: https://stackoverflow.com/a/66050613/5130269

Upvotes: 2

Related Questions