From owner-freebsd-hackers@FreeBSD.ORG Mon Oct 26 21:32:07 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 1DD7C106566B for ; Mon, 26 Oct 2009 21:32:07 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from server.mypc.hu (server.mypc.hu [87.229.73.95]) by mx1.freebsd.org (Postfix) with ESMTP id 915C48FC20 for ; Mon, 26 Oct 2009 21:32:06 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by server.mypc.hu (Postfix) with ESMTP id E908E14D99BB; Mon, 26 Oct 2009 22:07:05 +0100 (CET) X-Virus-Scanned: amavisd-new at example.com Received: from server.mypc.hu ([127.0.0.1]) by localhost (server.mypc.hu [127.0.0.1]) (amavisd-new, port 10024) with LMTP id isyRpEHgF8mG; Mon, 26 Oct 2009 22:07:03 +0100 (CET) Received: from [192.168.1.105] (catv-89-132-179-104.catv.broadband.hu [89.132.179.104]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by server.mypc.hu (Postfix) with ESMTPSA id 3237414D9A25; Mon, 26 Oct 2009 22:07:03 +0100 (CET) Message-ID: <4AE60F70.9070808@FreeBSD.org> Date: Mon, 26 Oct 2009 22:06:56 +0100 From: Gabor Kovesdan User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Oliver Mahmoudi References: <6b4b2d2c0910261308i367569dbg887d7c713bf20ad1@mail.gmail.com> In-Reply-To: <6b4b2d2c0910261308i367569dbg887d7c713bf20ad1@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit 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: Mon, 26 Oct 2009 21:32:07 -0000 Oliver Mahmoudi escribió: > I compiled the library file in the following way. > > % gcc -I../include -Wall -c lb.c > % ar rsv mylib.a lb.o > You can study bsd.lib.mk and bsd.prog.mk in /usr/share/mk. With these two includes you can deal easily with your C programs/libraries. It will serve you very well later. > The compilation finished with no warnings so I assume that there are no > errors in the library itself. > > Trying to compile my source file - let's call it source.c - I always get the > following error message: > > % gcc -o testfile source.c > /var/tmp//ccQoff1S.o(.text+0x19): In function `main': > : undefined reference to `myprintf' > % > > That's easy, your library isn't linked to your program. First, compile the source file but _do not link_: gcc -c source.c This will result in a source.o file. Then link the object files (source.o and the static library) with ld: ld -o testfile source.o mylib.a > In other words, gcc doesn't seem to find my library. I tried to mv my > library file in /lib, /libexec > /usr/lib, /usr/libdata and /usr/libexec but none of the above directories > would directory would > let me compile my source file. > > With static libraries you can just specify the full path when linking. > Now I am wondering where do I need to put mylib.a file to succeed? > > Also, this is a static library. What do I need to do under FreeBSD to > compile this library into a dynamic > library and where would I put this file? > Just using the proper parameters when compiling the library. It is a Linux article but you'll find some explications here: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html Again, the bsd.*.mk Makefile includes are pretty handful. > Lastly, most if not all the system calls can be found under /sys/kern/*.c. > When writing a FreeBSD C program > gcc makes use of the corresponding headers, e.g. unistd.h. and the standard > library libc. Is it possible > to peep a look at the source file for libc, i.e. is it included in the > source tree? Where? > In /usr/src/lib/libc provided you have the source code installed in /usr/src. > There are many many more kernel related questions on my mind but I think > that this is enought for one > email. > I don't want to desperate you but these are very basic things. You should get a deeper knowledge of the basics first, before you try to do some kernel-related things. Otherwise, you will find it way too difficult and you won't enjoy. Anyway, the book of Marshall K. McKusick and George V. Neville-Neil is a good source of learning kernel stuff: http://www.amazon.com/Design-Implementation-FreeBSD-Operating-System/dp/0201702452 Regards, -- Gabor Kovesdan FreeBSD Volunteer EMAIL: gabor@FreeBSD.org .:|:. gabor@kovesdan.org WEB: http://people.FreeBSD.org/~gabor .:|:. http://kovesdan.org