How do I add a Library Path to the Linker?

The linker can either be invoked by directly calling ld.lld or through the compiler driver clang. The general syntax to invoke ld.lld is as follows:

ld.lld <options> <input-files>

The following example shows how to produce an executable binary called <output> by linking together the contents of all <input object files> and the library lib<library-name>.a:

ld.lld -o <output> <input-object-files> -L<library-path> -l<library-name>

Instead of calling the linker directly, we recommend using the toolchain driver clang instead. It will automatically choose appropriate options and libraries based on the given options. Using clang, the example from above looks as follows:

clang -o <output> <input-object-files> -L<library-path> -l<library-name>