MetallicPriest
MetallicPriest

Reputation: 30765

How to include *.so file in makefile

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

Upvotes: 5

Views: 16534

Answers (1)

greg
greg

Reputation: 4953

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.

Upvotes: 8

Related Questions