How to include *.so file in makefile

13,709

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.

Share:
13,709
MetallicPriest
Author by

MetallicPriest

Updated on June 04, 2022

Comments

  • MetallicPriest
    MetallicPriest almost 2 years

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