From owner-freebsd-hackers@FreeBSD.ORG Mon Oct 26 20:36:08 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 BC84E1065694 for ; Mon, 26 Oct 2009 20:36:08 +0000 (UTC) (envelope-from olivermahmoudi@gmail.com) Received: from mail-bw0-f209.google.com (mail-bw0-f209.google.com [209.85.218.209]) by mx1.freebsd.org (Postfix) with ESMTP id 410D48FC12 for ; Mon, 26 Oct 2009 20:36:08 +0000 (UTC) Received: by bwz1 with SMTP id 1so2769184bwz.13 for ; Mon, 26 Oct 2009 13:36:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=f1/69KJ+L1aWaHwjaqwZQepiXkrXg2HwzU7sekf11CQ=; b=jC6QYs3TKLjfg9WxzxRHKAnWgvOVNjYZgLGimApy8v1vcTgsZOoCEXtRrC1w9sCfPU mJypoDTPG58eXOOl6d0B/qdUoYL3zQo2k2gzRAKHJqUXLJvvX0y5SjdRs7mF9fftIBHl A4Bd0BPL4wH9IbAWxl/tjNcWWZWV//r7zZzhE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=mtP3t7dBp6bh6z+92oc0Cg4OCWAfhBiKFpsypVVuFeHEY5BcA9fAg4ceWqtGnzjj9M PX5fBqfcsUbYxYPnhRRhAHTX2S1wNFCUlK+RbV/7i5CGgI3/WTePRGwahdszHOea4XkS oYgZ7GzMCLDsSJp/rMxO3c1P1W5vU2uizKzxs= MIME-Version: 1.0 Received: by 10.239.182.158 with SMTP id q30mr565287hbg.23.1256587696410; Mon, 26 Oct 2009 13:08:16 -0700 (PDT) Date: Mon, 26 Oct 2009 21:08:16 +0100 Message-ID: <6b4b2d2c0910261308i367569dbg887d7c713bf20ad1@mail.gmail.com> From: Oliver Mahmoudi To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: 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 20:36:08 -0000 Hello all y'all Kernel Hackers, Trying to get a deeper understanding of the FreeBSD kernel I am currently I am studying C library files. For this reason I wrote a very simple library, just to understand how it works. Below are my source codes for: 1. the header 2. the library file 3. a simple C program with which I intend to test my library function ############## start of simple library header ######################## #ifndef _s_lib_h_ #define _s_lib_h_ #define SOME_INT 0x0001 /* prototype */ void myprnf(char *); #endif /* _s_lib_h_ */ ##################### end of header ############################ ################# start of library file lb.c ########################## #include #include "slib.h" static void _myprf(char *); void myprnf(char *farg) { char *narg = farg; _myprf(narg); } static void _myprf(char *sarg) { char *pstr = sarg; printf("%s\n", pstr); } ############## end of library file ############################### ################ start of source file ############################ #include "slib.h" int main() { char *somestr = "hello world"; myprnf(somestr); return(1-1); } ################# end of source file ########################### I compiled the library file in the following way. % gcc -I../include -Wall -c lb.c % ar rsv mylib.a lb.o 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' % 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. 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? 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? Thanks Oliver There are many many more kernel related questions on my mind but I think that this is enought for one email.