Force GCC to static-link e.g. pthreads (and not dynamic link)

青春壹個敷衍的年華 提交于 2019-12-04 22:32:37

问题


My program is built as a loader and many modules which are shared libraries. Now one of those libraries uses pthreads and it seems its bound to the module dynamically (loaded on startup). Now it'd be simplier if i could force pthreads to be linked into the module file. GCC on linux, how do i do? I guess a libpthread.a is necessary....


回答1:


While linking libpthread.a into a shared library is theoretically possible, it is a really bad idea. The reason is that libpthread is part of glibc, and all parts of glibc must match exactly, or you'll see strange and un-explainable crashes.

So linking libpthread.a into your shared library will:

  1. Cause your program to crash when moved to a machine with a different version of glibc
  2. Cause your existing program to crash when your current machine's glibc is upgraded, but your module is not re-linked against updated libpthread.a.

Spare yourself aggravation, and don't do that.



来源:https://stackoverflow.com/questions/10390584/force-gcc-to-static-link-e-g-pthreads-and-not-dynamic-link

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