简体   繁体   English

Linux-为什么我的可执行文件将libpthread作为共享库?

[英]Linux - Why does my executable have libpthread as a shared library?

So basically I´d like to know why my executable has libpthread as a shared library whilst my code is not using any threading functions whatsoever. 因此,基本上我想知道为什么我的可执行文件将libpthread作为共享库,而我的代码却没有使用任何线程函数。 It isn´t included from the makefile either. 它也不包含在makefile中。 Is it because GCC is compiled by default with "--enable-threads=posix" ? 是因为GCC默认情况下是使用“ --enable-threads = posix”编译的?

If so is there a way to remove it from my executable? 如果是这样,有没有办法将其从我的可执行文件中删除? If not what is the problem? 如果不是,那是什么问题?

ldd dd

    linux-vdso.so.1 =>  (0x0000656150c5a000)
    librt.so.1 => /lib64/librt.so.1 (0x0000656150a4c000)
    libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000656150746000)
    libm.so.6 => /lib64/libm.so.6 (0x00006561504c1000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00006561502ab000)
    libc.so.6 => /lib64/libc.so.6 (0x000065614ff17000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x000065614fcf9000)
    /lib64/ld-linux-x86-64.so.2 (0x0000656150c5b000)

Makefile 生成文件

CC = gcc
OFLAGS = -O3

C++ = g++ -g
LFLAGS = -lrt

# API Exclusions
DFLAGS = -DNO_ZLIB -DNO_LOCALIZATION -DNO_INTERFACE

CFLAGS = $(OFLAGS) $(DFLAGS) -I. -I../rgapi/include/core/ -I../rgapi/include/public/

OBJS = ( ... list of .o files ... )
PROGS = ./rgs

all: $(OBJS) $(PROGS)

./rgs: $(OBJS)
    $(C++) -o ./rgs $(OBJS) $(LFLAGS)

clean:
    rm -f $(OBJS) $(PROGS)

$(OBJS): %.o: %.cpp
    $(C++) -o $@ $(CFLAGS) -c $<

./rgs: $(OBJS)

You are linking with librt.so : 您正在与librt.so链接:

LFLAGS = -lrt

This is an indirect dependency. 这是间接依赖关系。

$ ldd /usr/lib64/librt.so
    linux-vdso.so.1 (0x00007ffcc33d2000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2480a0b000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f2480649000)
    /lib64/ld-linux-x86-64.so.2 (0x0000562f4cffb000)

librt.so is linked with -lpthread . librt.so-lpthread链接。 If you link with any shared library, you inherit all the baggage that the shared library gets linked with. 如果您与任何共享库链接,那么您将继承与共享库链接的所有行李。

You cannot "remove it from your executable". 您不能“将其从可执行文件中删除”。 The only way to do so is not link with -lrt . 唯一的方法不是与-lrt链接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Linux可执行文件作为共享库 - Linux executable file as shared library Linux:为什么加载程序会找到我的共享库? - Linux: Why loader finds my shared library? 为什么ld需要我的可执行文件依赖的库? - Why does ld need library that my executable depends on? 为什么动态 linker *减去*虚拟地址以找出 memory 中加载的共享库可执行文件的位置? - Why does the dynamic linker *subtract* the virtual address to find out location of loaded shared library executable in memory? 共享库(.so)与 Linux 可执行文件之间的区别没有扩展名? - Difference between shared library (.so) a Linux executable file without extension? 为什么我在 build 目录中新建的共享库与 install 目录中的副本相比具有不同的依赖集? - Why does my newly built shared library in the build directory have a different set of dependencies compared to the copy in the install directory? Linux 可执行文件在同一文件夹中找不到共享库 - Linux executable can't find shared library in same folder 在Linux上具有静态C运行时的共享库和可执行链接。 他们每个人都有像Windows一样的单独堆吗? - Shared Libraries and Executable linking with static C run time on Linux. Does each of them have separate heap like Windows? 为什么Linux上的动态链接的可执行文件在其自己的内存空间中具有libc的完整内存空间? - Why does a dynamically linked executable on Linux have the complete memory space of libc in its own memory space? Linux共享库中的Singleton无法按预期工作 - Singleton in shared library in Linux does not work as expected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM