From owner-freebsd-hackers@FreeBSD.ORG Wed Nov 4 08:31:35 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 A5C88106566B for ; Wed, 4 Nov 2009 08:31:35 +0000 (UTC) (envelope-from olivermahmoudi@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.157]) by mx1.freebsd.org (Postfix) with ESMTP id 0BDD78FC1F for ; Wed, 4 Nov 2009 08:31:34 +0000 (UTC) Received: by fg-out-1718.google.com with SMTP id l26so728831fgb.13 for ; Wed, 04 Nov 2009 00:31:34 -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=gBMLAlj3yzG1V3oNDlVcyp8FJW1fY3UulSKWBIMPUT8=; b=fkv2HuKsAtbufjYHadfvUxrsKTdMyF5eHIBb2WgrBpA2Q9d7npmIRLTKtNJJox1/A8 ZBik5bLQm4Qq4aT3LPO3fUCEB1LTPIyVdutRGt2uTp2EOIOoawmj/V6LELyah2CjvwhV zqx4Ix2pqkqttQMwqc26EaZ/jh7PAaUMO01iU= 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=On6XqDAkSWH3Tcs8ZAqtPwP1laQNeL3LyY4pgJ7yWq1XCAfGQ/n1iFdph/GVa2993P iDpqhg2bLyw034FYl1Mh5kA42zta5PRNa/8+Fw+FE2Mp/wX5M28HWrhCGnJlhqZPuMud N9iCXpoEMBAPmaek45InBnvtZYcW8ltI74KNU= MIME-Version: 1.0 Received: by 10.239.182.164 with SMTP id q36mr125737hbg.87.1257323493868; Wed, 04 Nov 2009 00:31:33 -0800 (PST) In-Reply-To: <4AE60F70.9070808@FreeBSD.org> References: <6b4b2d2c0910261308i367569dbg887d7c713bf20ad1@mail.gmail.com> <4AE60F70.9070808@FreeBSD.org> Date: Wed, 4 Nov 2009 09:31:33 +0100 Message-ID: <6b4b2d2c0911040031h2175011dy949e4d368ffbb997@mail.gmail.com> From: Oliver Mahmoudi To: Gabor Kovesdan , f.loeber@googlemail.com Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-hackers@freebsd.org 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 08:31:35 -0000 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. Anyways, thanks again. Oliver >