From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 5 12:36:33 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 D707B1065675 for ; Thu, 5 Feb 2009 12:36:33 +0000 (UTC) (envelope-from pluknet@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.159]) by mx1.freebsd.org (Postfix) with ESMTP id 5F2CD8FC27 for ; Thu, 5 Feb 2009 12:36:33 +0000 (UTC) (envelope-from pluknet@gmail.com) Received: by fg-out-1718.google.com with SMTP id l26so134896fgb.35 for ; Thu, 05 Feb 2009 04:36:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=RSE7FUdQX3XFlriET7hFcFudHVgq6CBAtpZNxK7LTaY=; b=mLag/TuFniKkj0QgILT86TDADWfKQGNjFV/3kKewK156nNr3vJcl39iBAe0Kje+PL6 C5KSWEyF/flwsxoG6anvs7MlOZXztTAFZaHdg57aingBjfZwpradU1D8TLkqriXHOMPn sOX3ujClwkiUxURUhAU0rck/YlhdzPdmLaiBE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=MiiIAtdDq90rM3A47fAr29FRLK8d6agBZMNX34oIyOpersuUb69cuSOYOjkenAc/jo xb7rLoFMvZmV6qUKUEzZtG00S6GlmCJ6PraPjh7p2AZSymeEV8ne1w40i3aP7B+WHAzR SDsvvmZxozXDlMhVnLq5fMeghl0KUYcBHfqYI= MIME-Version: 1.0 Received: by 10.86.4.2 with SMTP id 2mr295345fgd.50.1233837392343; Thu, 05 Feb 2009 04:36:32 -0800 (PST) In-Reply-To: References: Date: Thu, 5 Feb 2009 15:36:32 +0300 Message-ID: From: pluknet To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 12:36:36 -0000 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. > > 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