linking .a lib with another library

pluknet pluknet at gmail.com
Thu Feb 5 04:36:36 PST 2009


2009/2/5 pluknet <pluknet at gmail.com>:
> Hi.
>
> The problem is:
>
> I have a program which is statically linked to my static lib during a build.
> The lib is in turn uses kvm*() calls, hence it should be linked with libkvm.
>
> During the build of my binaries which are linked to my libucron.a I
> get the following:
>
> /usr/home/pluknet/svn/ucron/ksucron/crond/../lib/libucron.a(misc.o)(.text+0x6e):
> In function `check_pidfile':
> : undefined reference to `kvm_open'
> /usr/home/pluknet/svn/ucron/ksucron/crond/../lib/libucron.a(misc.o)(.text+0x8b):
> In function `check_pidfile':
> : undefined reference to `kvm_getprocs'
> /usr/home/pluknet/svn/ucron/ksucron/crond/../lib/libucron.a(misc.o)(.text+0xbe):
> In function `check_pidfile':
> : undefined reference to `kvm_getprocs'
> /usr/home/pluknet/svn/ucron/ksucron/crond/../lib/libucron.a(misc.o)(.text+0x106):
> In function `check_pidfile':
> : undefined reference to `kvm_close'
> *** Error code 1
>
> Ok, if I add SHLIB_MAJOR directive in lib/Makefile (or remove any kvm*
> references) then all is ok.
> But the lib is used to be static. So the question is can I somehow
> link two .a libraries?
> e.g. libkvm.a + libucron.a + my binaries.
>

Ok, I finally got it:
gcc crond/crond.o lib/libucron.a /usr/lib/libkvm.a
-L/usr/local/lib/mysql -lmysqlclient

or in BNF (bmake normal form):
LDADD+=         -lmysqlclient -lucron ${LIBKVM}

$ ldd crond/crond
crond/crond:
        libmysqlclient.so.14 =>
/usr/local/lib/mysql/libmysqlclient.so.14 (0x28080000)
        libc.so.6 => /lib/libc.so.6 (0x280d5000)
        libcrypt.so.3 => /lib/libcrypt.so.3 (0x281ba000)
        libm.so.4 => /lib/libm.so.4 (0x281d2000)
        libz.so.3 => /lib/libz.so.3 (0x281e8000)

The only drawback is that I had to add that to crond/Makefile, not to
lib/Makefile.
crond knows nothing about kvm calls and now it has to (and lib does vice versa).

-- 
wbr,
pluknet


More information about the freebsd-hackers mailing list