Date: Mon, 26 Oct 2009 22:06:56 +0100 From: Gabor Kovesdan <gabor@FreeBSD.org> To: Oliver Mahmoudi <olivermahmoudi@gmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: writing a FreeBSD C library Message-ID: <4AE60F70.9070808@FreeBSD.org> In-Reply-To: <6b4b2d2c0910261308i367569dbg887d7c713bf20ad1@mail.gmail.com> References: <6b4b2d2c0910261308i367569dbg887d7c713bf20ad1@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4AE60F70.9070808>