如何使用ldconfig添加pthread库

发布于 2024-09-08 18:13:39 字数 364 浏览 0 评论 0原文

目前,在编译使用 pthread 库函数的 C 程序时,我必须显式指定编译器选项 -lpthread 。请建议一种配置 ldconfig 的方法,以便无需在命令行上指定即可使用 pthread 库。

目前 lpthread -p 给出以下输出:=

[root@localhost lib]# ldconfig -p | grep pthread
    libpthread.so.0 (libc6, OS ABI: Linux 2.6.9) => /lib/libpthread.so.0
    libOpenIPMIpthread.so.0 (libc6) => /usr/lib/libOpenIPMIpthread.so.0

Currently, while compiling a C program which uses pthread library function I have to specify compiler option -lpthread explicitly. Please suggest a way to configure ldconfig so that the pthread library could be used without specifying it on the command line.

presently lpthread -p gives the following output :=

[root@localhost lib]# ldconfig -p | grep pthread
    libpthread.so.0 (libc6, OS ABI: Linux 2.6.9) => /lib/libpthread.so.0
    libOpenIPMIpthread.so.0 (libc6) => /usr/lib/libOpenIPMIpthread.so.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

べ繥欢鉨o。 2024-09-15 18:13:39

我不相信你能做到这一点。 LD_LIBRARY_PATH 和 ldconfig 程序用于设置共享库的路径,这些共享库用于在运行时解决可执行文件中的依赖关系。

编译时,您必须指定在链接阶段包含哪些库,即 -lpthread

I don't believe you can do that. The LD_LIBRARY_PATH and ldconfig program are used to set up the paths to shared libraries that are used to resolve dependencies in your executable at runtime.

When compiling you will have to specify which libraries to include in the linking phase, i.e. -lpthread

得不到的就毁灭 2024-09-15 18:13:39

您可以设置 LD_LIBRARY_PATH 环境变量。

You can set the LD_LIBRARY_PATH env variable.

独守阴晴ぅ圆缺 2024-09-15 18:13:39

pthreads 库是一个动态库。这意味着,为了使用其功能,与二进制文件不同的文件必须在运行时可用。

您可以通过多种方式做到这一点。设置 -lpthread 将自动设置您想要的编译器标志。通过LD_PRELOAD提供共享文件也能起到同样的作用。或者您的 pthreaded 程序显式地 dlopen 库。

但正确的方法是提供正确的编译器开关。

The pthreads library is a dynamic library. This means that, in order to use its functionality, a file distinct from your binary must be available at run time.

You can do this in several ways. Setting -lpthread will automatically set the compiler flags you want. Providing the shared file via LD_PRELOAD will do the same. Or you have your pthreaded program dlopen the library explicitly.

But the right way to do it is to provide the right compiler switches.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文