Wednesday, August 17, 2005

Missing libraries when compiling with gcc

Missing libraries when compiling with gcc

I'm stumped on this one, and can't seem to (easily) find any solutions.

There are times when I try to compile open source packages which reference
librarys such as -lnet -lgd etc. In the most recent case, -lsnmp.

I have crle set to properly access all of my library directories, and have
even tried to force gcc to look at specific directories using
CFLAGS=-L... -I... I'm sure this is an easy-to-overcome problem, and the
solution is probably right in my face -- but I can't see it.

In my most recent case, I'm trying to recompile apcupsd with Net-SNMP. I'm
using the Net-SMTP package from SFW, which installs in /usr/local.
/usr/local/lib is in my crle reference, but the autoconf (configure) script
fails when trying to access -lsnmp or -lnetsnmp (I think that last one is
right, I cleared the screen yesterday :)

Any ideas or pointers in the right direction would be greatly appreciated,
and will earn a beer when in my neighborhood.

--
Alan W. Rateliff, II

> solution is probably right in my face -- but I can't see it.

CFLAGS tells the compiler where to find header files; crle tells the
run-time linker where to find libraries when you have failed to link your
binaries correctly. You have to set LDFLAGS to tell the compile time
linker where to find libraries and you use both -L and -R arguments.

For further enlightenment read the man pages ld(1) and ld.so.1(1).

> right, I cleared the screen yesterday :)

What does net-snmp-config print when invoked as:

% net-snmp-config --libs

?

> For further enlightenment read the man pages ld(1) and ld.so.1(1).

I have the same problem, but I'm a newbie and not very clear on what you
mean. Could you please elaborate a bit more on your reply? Thanks a lot!

> mean. Could you please elaborate a bit more on your reply? Thanks a lot!

Elaborate on what matter? Setting up crle is never required for binaries
which you build on the system properly. Moreover, if you set up crle
incorrectly you are going to be learning how to boot from CDROM to fix
your system.

CFLAGS and LDFLAGS are set in your environment and properly written
configure scripts will use them to create the Makefiles. On this system:

[~]$ echo $CFLAGS; echo $LDFLAGS
-O2 -pipe -mcpu=ultrasparc
-L/usr/sfw/lib -R/usr/sfw/lib -L/opt/sfw/lib -R/opt/sfw/lib
-L/usr/openwin/lib -R/usr/openwin/lib

> For further enlightenment read the man pages ld(1) and ld.so.1(1).

I have played with all of the above for a few hours and turned up the
following results. I also want to note that in the past I hed been
admonished to not use env variables during compile or run, thus my reliance
upon crle.

Browsing through config.log I determined that I was using the wrong version
of OpenSSL for this specific instance. I installed a new package and tried
again. The configure script failed again, but this time I determined that
several kstat_* references in libnetsnmp.so were UNDEF'd. libnetsnmp.so was
linked with -lkstat. Now I'm just working to resolve the -lkstat issue
easily.

I tried a few other programs which were giving me headaches in the past and
LDFLAGS seems to cure what ails them.

--

> I have played with all of the above for a few hours and turned up the
> following results. I also want to note that in the past I hed been
> admonished to not use env variables during compile or run, thus my reliance
> upon crle.

Whoever told you that did not understand what he was doing.

> Browsing through config.log I determined that I was using the wrong version
> of OpenSSL for this specific instance. I installed a new package and tried
> again. The configure script failed again, but this time I determined that
> several kstat_* references in libnetsnmp.so were UNDEF'd. libnetsnmp.so was
> linked with -lkstat. Now I'm just working to resolve the -lkstat issue
> easily.

Since libkstat.so is in /usr/lib I expect that your Makefile does not
contain that -lkstat directive. Take a close look at the last line of
your make output starting with "gcc" to see if it contains "-lkstat".

> I tried a few other programs which were giving me headaches in the past and
> LDFLAGS seems to cure what ails them.

Solaris binaries are ELF. The headers of the binaries are supposed to
contain the library search paths. They get those paths only if *you* link
them correctly, generally using the -R argument in your LDFLAGS. Some
configure scripts, notably the one in BIND, ignore your environment and you
need to edit the Makefiles in order to provide the runtime link paths.

> your make output starting with "gcc" to see if it contains "-lkstat".

In my case, libnetsnmp.so was linked with -lkstat, and a few others. So I

export LIBS="-lkstat -lm -lgen"

and voila. A shove in the right direction can work wonders. Thanks.

0 Comments:

Post a Comment

<< Home