Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between static and shared libraries in Android's NDK?

I'm new to Android's NDK and I don't understand the differences between static and shared libraries. What are they, and when would I choose one type over the other?

like image 761
hara Avatar asked Jul 09 '10 14:07

hara


People also ask

What is the difference between static library and shared library?

Static libraries take longer to execute, because loading into the memory happens every time while executing. While Shared libraries are faster because shared library code is already in the memory. In Static library no compatibility issue has been observed.

What is the difference between shared library and static library in IIB?

If a shared library is deployed in a BAR file, it can still be used by applications or shared libraries in other deployed BAR files. Static libraries are packaged and deployed in the same BAR file as the applications that reference them.

What are the differences between static and dynamic shared libraries?

What are the differences between static and dynamic libraries? Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.

Is static library faster than shared library?

Historically, libraries could only be static. They are usually faster than the shared libraries because a set of commonly used object files is put into a single library executable file.


1 Answers

The term shared library is not a perfect fit regarding Android's NDK, because in many cases the .so libraries aren't actually shared between applications. It's better to classify the libraries that the NDK builds as static and dynamic.

Every Android application is a Java application, and the only entry point for the NDK code is loading it as a dynamic library and call it trough JNI.

Static libraries are an archives of compiled object files. They get bundled in other libraries at build time. Unused portions of code from static libraries are stripped by the NDK to reduce total size.

Dynamic libraries are loaded at runtime from separate files. They can contain static libraries that they are dependent on or load more dynamic libraries.

So what you actually need for Android development is at least one shared library, that will be called from Java code, and linked with it's dependencies as static libraries preferably.

like image 113
ognian Avatar answered Oct 02 '22 03:10

ognian