From owner-freebsd-hackers@FreeBSD.ORG Wed Nov 4 09:27:31 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 D48031065670; Wed, 4 Nov 2009 09:27:31 +0000 (UTC) (envelope-from redcrash@gmail.com) Received: from mail-bw0-f213.google.com (mail-bw0-f213.google.com [209.85.218.213]) by mx1.freebsd.org (Postfix) with ESMTP id 281A58FC0C; Wed, 4 Nov 2009 09:27:30 +0000 (UTC) Received: by bwz5 with SMTP id 5so8821150bwz.3 for ; Wed, 04 Nov 2009 01:27:29 -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:cc:content-type; bh=cyFGNfqvkW8WokrWtU3aGFUVjTklc2LuAgIPlaovwzE=; b=oc4ZDnGC9kwhR/d3vsbjMZxnRuurng5qkreMZ8qfrK3+HmL4bKn8PbHvjmV/of4q1f Nxw0BK1tH93cq9XfItF9zxH02zVn/lgsKwQcF0cEwFQ52EBPCIR+EmjAf/RgCTeD7+Ie h9lw7Kt/xvKrJCOayoealMRj91FTicY5bLkcU= 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 :cc:content-type; b=r5MsOT1H6YvBHFI1YIxl7GiYU8yF+KcjoRjVGKDobAZpig6yxUCS2L1UnEtEbfRVuX JNO6oR0OGASsthUKobLS0b6m+VZOc/jU7lIqKhe+7E5WaW99vgSLY+BX8rgmR6hL5Nt3 7aJBSkRuZt7eeWzHL5k+vCplDs2+tebFwh04g= MIME-Version: 1.0 Received: by 10.204.34.3 with SMTP id j3mr1167924bkd.23.1257325345505; Wed, 04 Nov 2009 01:02:25 -0800 (PST) In-Reply-To: <6b4b2d2c0911040031h2175011dy949e4d368ffbb997@mail.gmail.com> References: <6b4b2d2c0910261308i367569dbg887d7c713bf20ad1@mail.gmail.com> <4AE60F70.9070808@FreeBSD.org> <6b4b2d2c0911040031h2175011dy949e4d368ffbb997@mail.gmail.com> Date: Wed, 4 Nov 2009 10:02:25 +0100 Message-ID: From: Harald Servat To: Oliver Mahmoudi Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-hackers@freebsd.org, f.loeber@googlemail.com, Gabor Kovesdan Subject: Re: writing a FreeBSD C 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: Wed, 04 Nov 2009 09:27:32 -0000 Hello Oliver, 2009/11/4 Oliver Mahmoudi > Thank you for your emails. > Neither one of the methods that you two suggested brought about the desired > solution, but I have solved it. > > using gcc for the plain source with the -I switch gives: > % gcc -o aprog aprog.c -I ~/mylib/ > /var/tmp//ccHrDiyd.o(.text+0x19): In function `main': > : undefined reference to `myprnf' > > creating an object file first and then linking with ld gives me: > % ld -o aprog aprog.o mylib.a > ld: warning: cannot find entry symbol _start; defaulting to > 0000000008048080 > mylib.a(lb.o)(.text+0x33): In function `_myprf': > : undefined reference to `puts' > > whereas placing mylib.a before the -o switch and then linking with ld > gives: > % ld mylib.a -o aprog aprog.o > ld: warning: cannot find entry symbol _start; defaulting to > 0000000008048080 > aprog.o(.text+0x19): In function `main': > : undefined reference to `myprnf' > > which is essentially the same message it gives when compiling and linking > with gcc in one step. The fact that the order of the arguments matters is > also mentioned somewhere in gcc(1) and ld(1). > > The solution was to simply compile and link it like so: > % gcc -o testfile aprog.c mylib.a > % ./testfile > hello world > % > > > This is in essence a synthesis of what you two suggested. > > I'm afraid that this is not the most common usage of libraries in the unix world. Libraries, typically, are called lib[SOMETHING].a (if they are static libraries) or lib[SOMETHING].so* (if they are shared libraries). In addition, the -l X option in the gcc compiler looks for libX.[a|so] in the all specified paths defined by -L, so in your first command gcc -o aprog aprog.c -I ~/mylib/ you're making gcc to look for for something called lib~/mylib/.[a|so] which I doubt it can be found. So, I suggest you to: 1.- Name your "mylib.a" into "libmylib.a" (or other name that begins with lib), 2.- add -L. to your 1st gcc invocation (in order to instruct gcc to look at the current directory, i.e., "."), and 3.- add -lmylib (if you called your library libmylib.a) to the gcc Your compile instruction, then, should look like gcc -o aproc aprog.c -L. -lmylib Regards. > > Anyways, thanks again. > > > Oliver > > > > > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" > -- _________________________________________________________________ Fry: You can see how I lived before I met you. Bender: You lived before you met me?! Fry: Yeah, lots of people did. Bender: Really?!