Sir Rogers Sir Rogers - 6 months ago 34
Linux Question

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. It isn´t included from the makefile either. Is it because GCC is compiled by default with "--enable-threads=posix" ?

If so is there a way to remove it from my executable? If not what is the problem?

ldd => (0x0000656150c5a000) => /lib64/ (0x0000656150a4c000) => /usr/lib64/ (0x0000656150746000) => /lib64/ (0x00006561504c1000) => /lib64/ (0x00006561502ab000) => /lib64/ (0x000065614ff17000) => /lib64/ (0x000065614fcf9000)
/lib64/ (0x0000656150c5b000)


CC = gcc

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

# API Exclusions

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)

rm -f $(OBJS) $(PROGS)

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

./rgs: $(OBJS)


You are linking with

LFLAGS = -lrt

This is an indirect dependency.

$ ldd /usr/lib64/ (0x00007ffcc33d2000) => /lib64/ (0x00007f2480a0b000) => /lib64/ (0x00007f2480649000)
    /lib64/ (0x0000562f4cffb000) is linked with -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.