nalzok
nalzok

Reputation: 16107

How do I know the path of libraries used by ld?

Say I'm building and linking my application with clang

clang -I/usr/local/include -c -o app.o main.c
clang -L/usr/local/lib -o app app.o -lfoo

How do I know where libfoo.a or libfoo.dylib is located? Is there a verbose mode?

It's possible to search /usr/lib and /usr/local/lib manually, but doing so would be too tedious when you use many libraries.

Upvotes: 3

Views: 1364

Answers (1)

Mike Kinghan
Mike Kinghan

Reputation: 61307

If the linker is GNU ld, pass the linker option --trace, e.g.

clang -L/usr/local/lib -o app app.o -lfoo -Wl,--trace

If the linker is Darwin mach-o ld, pass the linker option -t, e.g.

clang -L/usr/local/lib -o app app.o -lfoo -Wl,-t

The linker will then report the path of each object file, archive(member) or dynamic library that it loads.

Upvotes: 3

Related Questions