Add the location of a shared library when compiling

Shared libraries are usually loaded after a program starts running. If you are using gcc (the Gnu Compiler Collection), you can add a path to the directory where you can find a shared library such as, use the compiler flag --rpath as shown in the following makefile

LDFLAGS=-Wl,--rpath -Wl,$(DIR)

some:   some.c
        gcc -o $@ some.c -L $(DIR) -l some $(LDFLAGS)
to compile the output so that at runtime it looks in /arbitrary/directory/somewhere for the library. Note here the -Wl flag is a wrapper which tells the compiler to pass the following thing directly to the linker.
Copyright © Ben Bullock 2009-2017. All rights reserved. For comments, questions, and corrections, please email Ben Bullock ( or use the discussion group at Google Groups. / Privacy / Disclaimer