|
Home > Archive > Unix Programming > January 2004 > Library Flags - to which lib they refer (newbie)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Library Flags - to which lib they refer (newbie)
|
|
|
| Hello,
How can I know , when in a makefile I encounter linker -l flags,
to which libraies theses flags were meant for ?
For example:
-lz -lresolv
I assume that -lz refers to zlib : am I right ?
and I do not know to what -lresolv refers
and I want to use gtk-2 library
should I use -lgtk-x11-2.0 ? (If I am not wrong I saw
it somewhere).
or something else ?
How can I figure it out?
regards,
sting
| |
| Nils O. =?iso-8859-1?Q?Sel=E5sdal?= 2004-01-23, 5:00 pm |
| In article <2ff4a208.0311270349.12773982@posting.google.com>, Sting wrote:quote:
> Hello,
>
> How can I know , when in a makefile I encounter linker -l flags,
> to which libraies theses flags were meant for ?
>
> For example:
> -lz -lresolv
>
> I assume that -lz refers to zlib : am I right ?
> and I do not know to what -lresolv refers
probably /usr/lib/libresolv.so.x if your OS have a package manager
you might ask it what package that file belongs to.
(libresolv is a dns resolver..)
quote:
> and I want to use gtk-2 library
> should I use -lgtk-x11-2.0 ? (If I am not wrong I saw
> it somewhere).
For gtk2 you should use the output of
pkg-config gtk+-2.0 --cflags for compiling
and
pkg-config gtk+-2.0 --libs
for linking.quote:
> or something else ?
> How can I figure it out?
By reading documentation ;)
--
Vennlig hilsen/Best Regards
Nils Olav Selåsdal <NOS at Utel.no>
System Engineer
UtelSystems a/s
| |
| Nils O. =?iso-8859-1?Q?Sel=E5sdal?= 2004-01-23, 5:00 pm |
| In article <2ff4a208.0311270349.12773982@posting.google.com>, Sting wrote:quote:
> Hello,
>
> How can I know , when in a makefile I encounter linker -l flags,
> to which libraies theses flags were meant for ?
>
> For example:
> -lz -lresolv
>
> I assume that -lz refers to zlib : am I right ?
> and I do not know to what -lresolv refers
probably /usr/lib/libresolv.so.x if your OS have a package manager
you might ask it what package that file belongs to.
(libresolv is a dns resolver..)
quote:
> and I want to use gtk-2 library
> should I use -lgtk-x11-2.0 ? (If I am not wrong I saw
> it somewhere).
For gtk2 you should use the output of
pkg-config gtk+-2.0 --cflags for compiling
and
pkg-config gtk+-2.0 --libs
for linking.quote:
> or something else ?
> How can I figure it out?
By reading documentation ;)
--
Vennlig hilsen/Best Regards
Nils Olav Selåsdal <NOS at Utel.no>
System Engineer
UtelSystems a/s
| |
| Jens.Toerring@physik.fu-berlin.de 2004-01-23, 5:00 pm |
| Sting <zstingx@hotmail.com> wrote:quote:
> How can I know , when in a makefile I encounter linker -l flags,
> to which libraies theses flags were meant for ?
quote:
> For example:
> -lz -lresolv
quote:
> I assume that -lz refers to zlib : am I right ?
> and I do not know to what -lresolv refers
-lz makes the linker look for a file named 'libz.so' (or libz.a),
and -lresolv for 'libresolv.so'. In which directories it checks
for these files depends (at least for the GNU linker AFAIK) on
the contents of the file '/etc/ld.so.conf', and it always checks
in '/lib' and '/usr/lib'.
quote:
> and I want to use gtk-2 library
> should I use -lgtk-x11-2.0 ? (If I am not wrong I saw
> it somewhere).
Yes, that looks reasonable (as long as libgtk-x11-2.0.so exists
on your system in one of the directories the linker automatically
checks.
quote:
> or something else ?
> How can I figure it out?
You need to know which library you want to link against. Then
cut of the leading 'lib' from the name and replace it by '-l'.
Also cut off the '.so' bit at the end. If the library isn't in
one of the directories the linker searches you also need to
specify '-L/path/to/dir/where/lib/resides' *before* the '-l'
stuff.
When the linking ended successfully you can check that the
library you wanted to link against was correctly picked by
the linker by running 'ldd' on the executable.
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Jens.Toerring@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
| |
| Jens.Toerring@physik.fu-berlin.de 2004-01-23, 5:00 pm |
| Sting <zstingx@hotmail.com> wrote:quote:
> How can I know , when in a makefile I encounter linker -l flags,
> to which libraies theses flags were meant for ?
quote:
> For example:
> -lz -lresolv
quote:
> I assume that -lz refers to zlib : am I right ?
> and I do not know to what -lresolv refers
-lz makes the linker look for a file named 'libz.so' (or libz.a),
and -lresolv for 'libresolv.so'. In which directories it checks
for these files depends (at least for the GNU linker AFAIK) on
the contents of the file '/etc/ld.so.conf', and it always checks
in '/lib' and '/usr/lib'.
quote:
> and I want to use gtk-2 library
> should I use -lgtk-x11-2.0 ? (If I am not wrong I saw
> it somewhere).
Yes, that looks reasonable (as long as libgtk-x11-2.0.so exists
on your system in one of the directories the linker automatically
checks.
quote:
> or something else ?
> How can I figure it out?
You need to know which library you want to link against. Then
cut of the leading 'lib' from the name and replace it by '-l'.
Also cut off the '.so' bit at the end. If the library isn't in
one of the directories the linker searches you also need to
specify '-L/path/to/dir/where/lib/resides' *before* the '-l'
stuff.
When the linking ended successfully you can check that the
library you wanted to link against was correctly picked by
the linker by running 'ldd' on the executable.
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Jens.Toerring@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
|
|
|
|
|