writing a FreeBSD C library

Oliver Mahmoudi olivermahmoudi at gmail.com
Wed Nov 4 08:31:35 UTC 2009


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



>


More information about the freebsd-hackers mailing list