Xu Hui
Xu Hui

Reputation: 1265

How to obtain the path of a library

I can compile my executable file by follow commands

g++ -c main.cpp
g++ main.o -o my_exe -lmy

I do not need to specify the path of the libmy.a using -L path during link.

The libmy.a can automatically find by system.

Now I want to find the path of libmy.a but I have no idea where it is.

How can I obtain the full path of libmy.a?

Upvotes: 1

Views: 60

Answers (1)

Mike Kinghan
Mike Kinghan

Reputation: 61610

Instead of:-

g++ main.o -o my_exe -lmy

link your program with:-

g++ main.o -o my_exe -lmy -Wl,-trace

This will make g++ pass the diagnostic option -trace to the linker. The linker will print the pathname by which it locates every object file, shared library or static libary that it inputs. Inspect the output and you will find the full pathname of libmy.a

Upvotes: 1

Related Questions