Search code examples
androidandroid-ndk

Why do we need -static option to compile native android applications


I was trying to build a native android application. When I tried to run it, I got an error this file does not exist. With little bit google, I found I need put -static option in compilation. I did so and it worked. But I wonder why is this options is required? Is it anything to do with cross compilation?


Solution

  • The option -static produces a statically linked binary without any dependencies to shared libraries. This is done if the system on which the linking takes place uses different libraries as the system on which the binary will run. In most cases this is a hack to avoid problems with incompatible libraries. The disadvantage of a statically linked binary is, that it is much bigger than a shared linked one and it uses much more memory. Generally it is better to create a proper build environment, which makes it possible to dynamically link the shared libraries.