简体   繁体   中英

Compiling with prebuilt static library

I want to use ffmpeg in my android application, considering the size of built library, I decided to write a piece of c code that accomplishes a simple video task.

I have tested my code on my Mac and it compiles and works fine. Now for the NDK part, I can't get it compiled successfully, I have several questions, and hoping for someone to give me a guide.

  1. Can I just cross compile my c code with static ffmpeg library installed on my Mac ? Or if I have to cross compile them before using in my code?
  2. The size of static library is 10Mb, and my c code is only a few lines, how big will be my final shared library ? About 10Mb ?

Any explanation will be appreciated 🙂

  1. Of course, the static lib needs to target the same architecture, so this has to be cross-compiled as well.

  2. It depends on the structure of the static lib. A static lib is normally just an archive of the object ( .o ) files. So if your library has sufficiently small translation units, and your program uses only a few of them, only these will really be linked to your executable. The outcome might be even smaller if the library and your program are compiled with -ffunction-sections -fdata-sections (which put all functions and all objects of static storage in their own segment) and then you pass -Wl,--gc-sections during linking, so any unused section is discarded. On the other hand, you could run in a situation that you call some functionality of the lib that internally needs close to all other library code, so you end up with nearly the whole library linked into your executable. Therefore: it depends, try it out, and if you're concerned about size, give --gc-sections a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM