Compile a Standalone Static Executable

拟墨画扇 提交于 2019-11-28 03:41:16

Try using the -static flag?

Use the following flags for linking

-static -static-libgcc -static-libstdc++

Use these three flags to link against the static versions of all dependencies (assuming gcc). Note, that in certain situation you don't necessarily need all three flags, but they don't "hurt" either. Therefore just turn on all three.

Check if it actually worked

  1. Make sure that there is really no dynamic linkage

    ldd yourexecutable
    

    should return "not a dynamic executable" or something equivalent.

  2. Make sure that there are no unresolved symbols left

    nm yourexecutable | grep " U "
    

    The list should be empty or should contain only some special kernel-space symbols like

    U __tls_get_addr
    
  3. Finally, check if you can actually execute your executable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!