From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 5 17:24:24 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 643F91065689 for ; Thu, 5 Feb 2009 17:24:24 +0000 (UTC) (envelope-from prvs=julian=280504c31@elischer.org) Received: from smtp-outbound.ironport.com (smtp-outbound.ironport.com [63.251.108.112]) by mx1.freebsd.org (Postfix) with ESMTP id 4EC788FC19 for ; Thu, 5 Feb 2009 17:24:24 +0000 (UTC) (envelope-from prvs=julian=280504c31@elischer.org) Received: from unknown (HELO julian-mac.elischer.org) ([10.251.60.88]) by smtp-outbound.ironport.com with ESMTP; 05 Feb 2009 09:11:40 -0800 Message-ID: <498B1DCB.801@elischer.org> Date: Thu, 05 Feb 2009 09:11:39 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.19 (Macintosh/20081209) MIME-Version: 1.0 To: pluknet References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org Subject: Re: linking .a lib with another library X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Feb 2009 17:24:25 -0000 pluknet wrote: > 2009/2/5 pluknet : >> 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. in static linking order is important.. you need to put libkvm after the library that has the refrences. (At least that is my first reaction) >> >> 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). >