5

For a program I was linking the static glibc library (which I modified). My makefile looks something like this.

CXX = g++
CXXFILES = main.c

CXXFLAGS = -g -o prog -D_GNU_SOURCE
LIBS = ../../nptl/libpthread.a ../../libc.a -lpthread

all:
    $(CXX) $(CXXFILES) $(LIBS) $(CXXFLAGS)

However, instead of using the static *.a files, I now want to use the dynamic shared object *.so files. Is it enough to replace the *.a files by *.so files in the makefile. If not what is the correct way of doing so. I tried to simply replace the *.a with *.so files in the makefile, but it seems like when I do that the program uses the original glibc (rather than my modified one).

MetallicPriest
  • 29,191
  • 52
  • 200
  • 356

1 Answers1

8

If you don't want to use the standard libraries, you might need the -nostdlib flag. In addition, if you want to dynamically link libraries, you need to tell the linker where they are. -L/dir/containing -lc.

If you don't want to set a LD_LIBRARY_PATH when executing, you'll need to set rpath, -Wl,--rpath=/path/containing.

greg
  • 4,843
  • 32
  • 47
  • 1
    Points for pointing out what `--rpath` does. So that's why so many projects I've downloaded require `LD_LIBRARY_PATH` in their build. – hellork Nov 24 '18 at 18:17