Date: Mon, 26 Oct 2009 21:08:16 +0100 From: Oliver Mahmoudi <olivermahmoudi@gmail.com> To: freebsd-hackers@freebsd.org Subject: writing a FreeBSD C library Message-ID: <6b4b2d2c0910261308i367569dbg887d7c713bf20ad1@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
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 <stdio.h> #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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6b4b2d2c0910261308i367569dbg887d7c713bf20ad1>