Find out if library is in path
Clash Royale CLAN TAG#URR8PPP
up vote
9
down vote
favorite
Assuming I want to test if a library is installed and usable by a program. I can use ldconfig -p | grep mylib
to find out if it's installed on the system. but what if the library is only known via setting LD_LIBRARY_PATH
?
In that case, the program may be able to find the library, but ldconfig
won't. How can I check if the library is in the combined linker path?
I'll add that I'm looking for a solution that will work even if I don't actually have the program at hand (e.g. the program isn't compiled yet), I just want to know that a certain library exists in ld
's paths.
linux dynamic-linking ld
add a comment |
up vote
9
down vote
favorite
Assuming I want to test if a library is installed and usable by a program. I can use ldconfig -p | grep mylib
to find out if it's installed on the system. but what if the library is only known via setting LD_LIBRARY_PATH
?
In that case, the program may be able to find the library, but ldconfig
won't. How can I check if the library is in the combined linker path?
I'll add that I'm looking for a solution that will work even if I don't actually have the program at hand (e.g. the program isn't compiled yet), I just want to know that a certain library exists in ld
's paths.
linux dynamic-linking ld
2
You could useldd <binary>
to check if all libraries linked are in the path. Maybe there is a more elegant way.
– Thomas
May 10 '16 at 9:33
@Thomas I think you should make an answer of your comment.ldd
serves exactly this purpose.
– lgeorget
May 10 '16 at 9:41
1
@Thomas - but what if I the program isn't compiled yet, and that library is needed for compilation?
– nbubis
May 10 '16 at 9:41
@Igeorget - see my edit / comment
– nbubis
May 10 '16 at 9:44
@nbubis: when you need the library for compilation, you normally have to useLIBRARY_PATH
environment variable which is looked up e.g. by thegcc
compiler. TheLIBRARY_PATH
environment variable also has a colon seperated list of directories.
– Thomas
May 10 '16 at 10:09
add a comment |
up vote
9
down vote
favorite
up vote
9
down vote
favorite
Assuming I want to test if a library is installed and usable by a program. I can use ldconfig -p | grep mylib
to find out if it's installed on the system. but what if the library is only known via setting LD_LIBRARY_PATH
?
In that case, the program may be able to find the library, but ldconfig
won't. How can I check if the library is in the combined linker path?
I'll add that I'm looking for a solution that will work even if I don't actually have the program at hand (e.g. the program isn't compiled yet), I just want to know that a certain library exists in ld
's paths.
linux dynamic-linking ld
Assuming I want to test if a library is installed and usable by a program. I can use ldconfig -p | grep mylib
to find out if it's installed on the system. but what if the library is only known via setting LD_LIBRARY_PATH
?
In that case, the program may be able to find the library, but ldconfig
won't. How can I check if the library is in the combined linker path?
I'll add that I'm looking for a solution that will work even if I don't actually have the program at hand (e.g. the program isn't compiled yet), I just want to know that a certain library exists in ld
's paths.
linux dynamic-linking ld
linux dynamic-linking ld
edited May 10 '16 at 10:57
Thomas Dickey
51.4k594164
51.4k594164
asked May 10 '16 at 9:05
nbubis
3792417
3792417
2
You could useldd <binary>
to check if all libraries linked are in the path. Maybe there is a more elegant way.
– Thomas
May 10 '16 at 9:33
@Thomas I think you should make an answer of your comment.ldd
serves exactly this purpose.
– lgeorget
May 10 '16 at 9:41
1
@Thomas - but what if I the program isn't compiled yet, and that library is needed for compilation?
– nbubis
May 10 '16 at 9:41
@Igeorget - see my edit / comment
– nbubis
May 10 '16 at 9:44
@nbubis: when you need the library for compilation, you normally have to useLIBRARY_PATH
environment variable which is looked up e.g. by thegcc
compiler. TheLIBRARY_PATH
environment variable also has a colon seperated list of directories.
– Thomas
May 10 '16 at 10:09
add a comment |
2
You could useldd <binary>
to check if all libraries linked are in the path. Maybe there is a more elegant way.
– Thomas
May 10 '16 at 9:33
@Thomas I think you should make an answer of your comment.ldd
serves exactly this purpose.
– lgeorget
May 10 '16 at 9:41
1
@Thomas - but what if I the program isn't compiled yet, and that library is needed for compilation?
– nbubis
May 10 '16 at 9:41
@Igeorget - see my edit / comment
– nbubis
May 10 '16 at 9:44
@nbubis: when you need the library for compilation, you normally have to useLIBRARY_PATH
environment variable which is looked up e.g. by thegcc
compiler. TheLIBRARY_PATH
environment variable also has a colon seperated list of directories.
– Thomas
May 10 '16 at 10:09
2
2
You could use
ldd <binary>
to check if all libraries linked are in the path. Maybe there is a more elegant way.– Thomas
May 10 '16 at 9:33
You could use
ldd <binary>
to check if all libraries linked are in the path. Maybe there is a more elegant way.– Thomas
May 10 '16 at 9:33
@Thomas I think you should make an answer of your comment.
ldd
serves exactly this purpose.– lgeorget
May 10 '16 at 9:41
@Thomas I think you should make an answer of your comment.
ldd
serves exactly this purpose.– lgeorget
May 10 '16 at 9:41
1
1
@Thomas - but what if I the program isn't compiled yet, and that library is needed for compilation?
– nbubis
May 10 '16 at 9:41
@Thomas - but what if I the program isn't compiled yet, and that library is needed for compilation?
– nbubis
May 10 '16 at 9:41
@Igeorget - see my edit / comment
– nbubis
May 10 '16 at 9:44
@Igeorget - see my edit / comment
– nbubis
May 10 '16 at 9:44
@nbubis: when you need the library for compilation, you normally have to use
LIBRARY_PATH
environment variable which is looked up e.g. by the gcc
compiler. The LIBRARY_PATH
environment variable also has a colon seperated list of directories.– Thomas
May 10 '16 at 10:09
@nbubis: when you need the library for compilation, you normally have to use
LIBRARY_PATH
environment variable which is looked up e.g. by the gcc
compiler. The LIBRARY_PATH
environment variable also has a colon seperated list of directories.– Thomas
May 10 '16 at 10:09
add a comment |
3 Answers
3
active
oldest
votes
up vote
9
down vote
accepted
ldconfig
can list all the libraries it has access to. These libraries are also stored in its cache.
/sbin/ldconfig -v -N
will crawl all the usual library paths, list all the available libraries, without reconstructing the cache (which is not possible if you're a non-root user). It does NOT take into account libraries in LD_LIBRARY_PATH (contrarily to what this post said before edit) but you can pass additional libraries to the command line by using the line below:
/sbin/ldconfig -N -v $(sed 's/:/ /g' <<< $LD_LIBRARY_PATH)
ldconfig is a tool from the 1980s that was given up in the 1990s. For this reason,ldconfig
is not portable as it only applies to implementations that are based on the SunOS-4.0a.out
based dynamic linker from 1987.
– schily
May 10 '16 at 10:00
How does that help listing libs which are only on LD_LIBRARY_PATH? I guess I could write a script to parse that and then read that through ldconfig, but it seems a bit like an over kill.
– nbubis
May 10 '16 at 10:10
1
@nbubis you can always pass the libraries in LD_LIBRARY_PATH to ldconfig. Like/sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH)
not too much of an overkill to my taste.
– lgeorget
May 10 '16 at 10:32
@schily Really? It works pretty well with ELF libraries as far as I can tell. And it's still used, ld.so relies on the cache built by ldconfig.
– lgeorget
May 10 '16 at 10:33
The Linux people hacked the old Sun linker source-code to support ELF. The new ELF implementation from Sun removedldconfig
in an agreement with AT&T as the linker caching was too sensitive to errors. Sun later addedthe tree stooges
:moe
,lari
andcrle
as helper programs for ELF management.
– schily
May 10 '16 at 10:52
|
show 1 more comment
up vote
1
down vote
Globally substitute (space) for :
with LD_LIBRARY_PATH
/sbin/ldconfig -N -v $(sed 's/:/ /g' <<< $LD_LIBRARY_PATH)
add a comment |
up vote
0
down vote
You can compile a simple test program with gcc and link your library. Then you can check the used libraries with ldd. I use something like this:
echo "int main()" | gcc -Wl,--no-as-needed -lmylib /tmp/test.c && ldd a.out | grep mylib
-Wl,--no-as-needed
prevents the linker from discarding the library, because no symbols from the library are used.
New contributor
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
9
down vote
accepted
ldconfig
can list all the libraries it has access to. These libraries are also stored in its cache.
/sbin/ldconfig -v -N
will crawl all the usual library paths, list all the available libraries, without reconstructing the cache (which is not possible if you're a non-root user). It does NOT take into account libraries in LD_LIBRARY_PATH (contrarily to what this post said before edit) but you can pass additional libraries to the command line by using the line below:
/sbin/ldconfig -N -v $(sed 's/:/ /g' <<< $LD_LIBRARY_PATH)
ldconfig is a tool from the 1980s that was given up in the 1990s. For this reason,ldconfig
is not portable as it only applies to implementations that are based on the SunOS-4.0a.out
based dynamic linker from 1987.
– schily
May 10 '16 at 10:00
How does that help listing libs which are only on LD_LIBRARY_PATH? I guess I could write a script to parse that and then read that through ldconfig, but it seems a bit like an over kill.
– nbubis
May 10 '16 at 10:10
1
@nbubis you can always pass the libraries in LD_LIBRARY_PATH to ldconfig. Like/sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH)
not too much of an overkill to my taste.
– lgeorget
May 10 '16 at 10:32
@schily Really? It works pretty well with ELF libraries as far as I can tell. And it's still used, ld.so relies on the cache built by ldconfig.
– lgeorget
May 10 '16 at 10:33
The Linux people hacked the old Sun linker source-code to support ELF. The new ELF implementation from Sun removedldconfig
in an agreement with AT&T as the linker caching was too sensitive to errors. Sun later addedthe tree stooges
:moe
,lari
andcrle
as helper programs for ELF management.
– schily
May 10 '16 at 10:52
|
show 1 more comment
up vote
9
down vote
accepted
ldconfig
can list all the libraries it has access to. These libraries are also stored in its cache.
/sbin/ldconfig -v -N
will crawl all the usual library paths, list all the available libraries, without reconstructing the cache (which is not possible if you're a non-root user). It does NOT take into account libraries in LD_LIBRARY_PATH (contrarily to what this post said before edit) but you can pass additional libraries to the command line by using the line below:
/sbin/ldconfig -N -v $(sed 's/:/ /g' <<< $LD_LIBRARY_PATH)
ldconfig is a tool from the 1980s that was given up in the 1990s. For this reason,ldconfig
is not portable as it only applies to implementations that are based on the SunOS-4.0a.out
based dynamic linker from 1987.
– schily
May 10 '16 at 10:00
How does that help listing libs which are only on LD_LIBRARY_PATH? I guess I could write a script to parse that and then read that through ldconfig, but it seems a bit like an over kill.
– nbubis
May 10 '16 at 10:10
1
@nbubis you can always pass the libraries in LD_LIBRARY_PATH to ldconfig. Like/sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH)
not too much of an overkill to my taste.
– lgeorget
May 10 '16 at 10:32
@schily Really? It works pretty well with ELF libraries as far as I can tell. And it's still used, ld.so relies on the cache built by ldconfig.
– lgeorget
May 10 '16 at 10:33
The Linux people hacked the old Sun linker source-code to support ELF. The new ELF implementation from Sun removedldconfig
in an agreement with AT&T as the linker caching was too sensitive to errors. Sun later addedthe tree stooges
:moe
,lari
andcrle
as helper programs for ELF management.
– schily
May 10 '16 at 10:52
|
show 1 more comment
up vote
9
down vote
accepted
up vote
9
down vote
accepted
ldconfig
can list all the libraries it has access to. These libraries are also stored in its cache.
/sbin/ldconfig -v -N
will crawl all the usual library paths, list all the available libraries, without reconstructing the cache (which is not possible if you're a non-root user). It does NOT take into account libraries in LD_LIBRARY_PATH (contrarily to what this post said before edit) but you can pass additional libraries to the command line by using the line below:
/sbin/ldconfig -N -v $(sed 's/:/ /g' <<< $LD_LIBRARY_PATH)
ldconfig
can list all the libraries it has access to. These libraries are also stored in its cache.
/sbin/ldconfig -v -N
will crawl all the usual library paths, list all the available libraries, without reconstructing the cache (which is not possible if you're a non-root user). It does NOT take into account libraries in LD_LIBRARY_PATH (contrarily to what this post said before edit) but you can pass additional libraries to the command line by using the line below:
/sbin/ldconfig -N -v $(sed 's/:/ /g' <<< $LD_LIBRARY_PATH)
edited May 9 at 16:51
Community♦
1
1
answered May 10 '16 at 9:46
lgeorget
8,75622450
8,75622450
ldconfig is a tool from the 1980s that was given up in the 1990s. For this reason,ldconfig
is not portable as it only applies to implementations that are based on the SunOS-4.0a.out
based dynamic linker from 1987.
– schily
May 10 '16 at 10:00
How does that help listing libs which are only on LD_LIBRARY_PATH? I guess I could write a script to parse that and then read that through ldconfig, but it seems a bit like an over kill.
– nbubis
May 10 '16 at 10:10
1
@nbubis you can always pass the libraries in LD_LIBRARY_PATH to ldconfig. Like/sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH)
not too much of an overkill to my taste.
– lgeorget
May 10 '16 at 10:32
@schily Really? It works pretty well with ELF libraries as far as I can tell. And it's still used, ld.so relies on the cache built by ldconfig.
– lgeorget
May 10 '16 at 10:33
The Linux people hacked the old Sun linker source-code to support ELF. The new ELF implementation from Sun removedldconfig
in an agreement with AT&T as the linker caching was too sensitive to errors. Sun later addedthe tree stooges
:moe
,lari
andcrle
as helper programs for ELF management.
– schily
May 10 '16 at 10:52
|
show 1 more comment
ldconfig is a tool from the 1980s that was given up in the 1990s. For this reason,ldconfig
is not portable as it only applies to implementations that are based on the SunOS-4.0a.out
based dynamic linker from 1987.
– schily
May 10 '16 at 10:00
How does that help listing libs which are only on LD_LIBRARY_PATH? I guess I could write a script to parse that and then read that through ldconfig, but it seems a bit like an over kill.
– nbubis
May 10 '16 at 10:10
1
@nbubis you can always pass the libraries in LD_LIBRARY_PATH to ldconfig. Like/sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH)
not too much of an overkill to my taste.
– lgeorget
May 10 '16 at 10:32
@schily Really? It works pretty well with ELF libraries as far as I can tell. And it's still used, ld.so relies on the cache built by ldconfig.
– lgeorget
May 10 '16 at 10:33
The Linux people hacked the old Sun linker source-code to support ELF. The new ELF implementation from Sun removedldconfig
in an agreement with AT&T as the linker caching was too sensitive to errors. Sun later addedthe tree stooges
:moe
,lari
andcrle
as helper programs for ELF management.
– schily
May 10 '16 at 10:52
ldconfig is a tool from the 1980s that was given up in the 1990s. For this reason,
ldconfig
is not portable as it only applies to implementations that are based on the SunOS-4.0 a.out
based dynamic linker from 1987.– schily
May 10 '16 at 10:00
ldconfig is a tool from the 1980s that was given up in the 1990s. For this reason,
ldconfig
is not portable as it only applies to implementations that are based on the SunOS-4.0 a.out
based dynamic linker from 1987.– schily
May 10 '16 at 10:00
How does that help listing libs which are only on LD_LIBRARY_PATH? I guess I could write a script to parse that and then read that through ldconfig, but it seems a bit like an over kill.
– nbubis
May 10 '16 at 10:10
How does that help listing libs which are only on LD_LIBRARY_PATH? I guess I could write a script to parse that and then read that through ldconfig, but it seems a bit like an over kill.
– nbubis
May 10 '16 at 10:10
1
1
@nbubis you can always pass the libraries in LD_LIBRARY_PATH to ldconfig. Like
/sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH)
not too much of an overkill to my taste.– lgeorget
May 10 '16 at 10:32
@nbubis you can always pass the libraries in LD_LIBRARY_PATH to ldconfig. Like
/sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH)
not too much of an overkill to my taste.– lgeorget
May 10 '16 at 10:32
@schily Really? It works pretty well with ELF libraries as far as I can tell. And it's still used, ld.so relies on the cache built by ldconfig.
– lgeorget
May 10 '16 at 10:33
@schily Really? It works pretty well with ELF libraries as far as I can tell. And it's still used, ld.so relies on the cache built by ldconfig.
– lgeorget
May 10 '16 at 10:33
The Linux people hacked the old Sun linker source-code to support ELF. The new ELF implementation from Sun removed
ldconfig
in an agreement with AT&T as the linker caching was too sensitive to errors. Sun later added the tree stooges
: moe
, lari
and crle
as helper programs for ELF management.– schily
May 10 '16 at 10:52
The Linux people hacked the old Sun linker source-code to support ELF. The new ELF implementation from Sun removed
ldconfig
in an agreement with AT&T as the linker caching was too sensitive to errors. Sun later added the tree stooges
: moe
, lari
and crle
as helper programs for ELF management.– schily
May 10 '16 at 10:52
|
show 1 more comment
up vote
1
down vote
Globally substitute (space) for :
with LD_LIBRARY_PATH
/sbin/ldconfig -N -v $(sed 's/:/ /g' <<< $LD_LIBRARY_PATH)
add a comment |
up vote
1
down vote
Globally substitute (space) for :
with LD_LIBRARY_PATH
/sbin/ldconfig -N -v $(sed 's/:/ /g' <<< $LD_LIBRARY_PATH)
add a comment |
up vote
1
down vote
up vote
1
down vote
Globally substitute (space) for :
with LD_LIBRARY_PATH
/sbin/ldconfig -N -v $(sed 's/:/ /g' <<< $LD_LIBRARY_PATH)
Globally substitute (space) for :
with LD_LIBRARY_PATH
/sbin/ldconfig -N -v $(sed 's/:/ /g' <<< $LD_LIBRARY_PATH)
edited Dec 14 '17 at 19:38
Stephen Rauch
3,308101328
3,308101328
answered Dec 14 '17 at 19:17
fizwit
112
112
add a comment |
add a comment |
up vote
0
down vote
You can compile a simple test program with gcc and link your library. Then you can check the used libraries with ldd. I use something like this:
echo "int main()" | gcc -Wl,--no-as-needed -lmylib /tmp/test.c && ldd a.out | grep mylib
-Wl,--no-as-needed
prevents the linker from discarding the library, because no symbols from the library are used.
New contributor
add a comment |
up vote
0
down vote
You can compile a simple test program with gcc and link your library. Then you can check the used libraries with ldd. I use something like this:
echo "int main()" | gcc -Wl,--no-as-needed -lmylib /tmp/test.c && ldd a.out | grep mylib
-Wl,--no-as-needed
prevents the linker from discarding the library, because no symbols from the library are used.
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
You can compile a simple test program with gcc and link your library. Then you can check the used libraries with ldd. I use something like this:
echo "int main()" | gcc -Wl,--no-as-needed -lmylib /tmp/test.c && ldd a.out | grep mylib
-Wl,--no-as-needed
prevents the linker from discarding the library, because no symbols from the library are used.
New contributor
You can compile a simple test program with gcc and link your library. Then you can check the used libraries with ldd. I use something like this:
echo "int main()" | gcc -Wl,--no-as-needed -lmylib /tmp/test.c && ldd a.out | grep mylib
-Wl,--no-as-needed
prevents the linker from discarding the library, because no symbols from the library are used.
New contributor
New contributor
answered Nov 19 at 16:08
guini
1011
1011
New contributor
New contributor
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f282199%2ffind-out-if-library-is-in-path%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
You could use
ldd <binary>
to check if all libraries linked are in the path. Maybe there is a more elegant way.– Thomas
May 10 '16 at 9:33
@Thomas I think you should make an answer of your comment.
ldd
serves exactly this purpose.– lgeorget
May 10 '16 at 9:41
1
@Thomas - but what if I the program isn't compiled yet, and that library is needed for compilation?
– nbubis
May 10 '16 at 9:41
@Igeorget - see my edit / comment
– nbubis
May 10 '16 at 9:44
@nbubis: when you need the library for compilation, you normally have to use
LIBRARY_PATH
environment variable which is looked up e.g. by thegcc
compiler. TheLIBRARY_PATH
environment variable also has a colon seperated list of directories.– Thomas
May 10 '16 at 10:09