本文介绍了强制GCC静态链接例如pthreads(而不是动态链接)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序是作为一个加载程序和许多共享库的模块构建的。现在,其中一个库使用pthread,它似乎是动态绑定到模块的(在启动时加载的)。现在它会更简单,如果我可以强制pthreads链接到模块文件。 GCC在Linux上,我该怎么办?我想libpthread.a是必要的。

解决方案

当链接 libpthread.a 在理论上是可行的,但这是一个非常糟糕的主意。原因是 libpthread 是 glibc 和所有所有部分的一部分$ c> glibc must 必须完全匹配,否则您会看到奇怪且无法解释的崩溃。

将 libpthread.a 链接到共享库中:


  1. 导致程序崩溃当移动到具有不同版本的 glibc

  2. 的机器上时,会导致现有程序在当前机器的 glibc 已升级,但您的模块未与更新的 libpthread.a 重新链接。

让自己加重,不要那样做。


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....

解决方案

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.

这篇关于强制GCC静态链接例如pthreads(而不是动态链接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 12:47