Why is the shared library path hard coded in executable?

I recently got a binary test. When I checked it with objdump, I found that it contains a hard-coded library path. Why do I need to hard-code such a path? Shouldn’t you get the path from the SHELL environment variable or -L parameter?

objdump -p testprog

The output includes the hard-coded path of the shared library:

....
NEEDED /home/test/lib/liba.so
NEEDED /home/test/lib/libb.so
NEEDED /home/ test/lib/libc.so
....

This may be because of this The three .so files do not have SONAME on the host that built the test program. Tell the person who built it to rebuild liba.so with -Wl, soname, liba.so and two other similar methods, and then relink the main program.

Recently I got a binary test. When I checked it with objdump, I found that it contains a hard-coded library path. Why do I need to hard-code such a path? Shouldn’t you get the path from the SHELL environment variable or -L parameter?

objdump -p testprog

The output includes the hard-coded path of the shared library:

....
NEEDED /home/test/lib/liba.so
NEEDED /home/test/lib/libb.so
NEEDED /home/ test/lib/libc.so
....

This may be because these three .so files are on the host where the test program is built There is no SONAME. Tell the person who built it to rebuild liba.so with -Wl, soname, liba.so and two other similar methods, and then relink the main program.

Leave a Comment

Your email address will not be published.