Date: Wed, 4 Nov 2009 10:02:25 +0100 From: Harald Servat <redcrash@gmail.com> To: Oliver Mahmoudi <olivermahmoudi@gmail.com> Cc: freebsd-hackers@freebsd.org, f.loeber@googlemail.com, Gabor Kovesdan <gabor@freebsd.org> Subject: Re: writing a FreeBSD C library Message-ID: <d825e0270911040102u40e10af7m16bc1137b48173fe@mail.gmail.com> In-Reply-To: <6b4b2d2c0911040031h2175011dy949e4d368ffbb997@mail.gmail.com> References: <6b4b2d2c0910261308i367569dbg887d7c713bf20ad1@mail.gmail.com> <4AE60F70.9070808@FreeBSD.org> <6b4b2d2c0911040031h2175011dy949e4d368ffbb997@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Hello Oliver, 2009/11/4 Oliver Mahmoudi <olivermahmoudi@gmail.com> > 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. > > I'm afraid that this is not the most common usage of libraries in the unix world. Libraries, typically, are called lib[SOMETHING].a (if they are static libraries) or lib[SOMETHING].so* (if they are shared libraries). In addition, the -l X option in the gcc compiler looks for libX.[a|so] in the all specified paths defined by -L, so in your first command gcc -o aprog aprog.c -I ~/mylib/ you're making gcc to look for for something called lib~/mylib/.[a|so] which I doubt it can be found. So, I suggest you to: 1.- Name your "mylib.a" into "libmylib.a" (or other name that begins with lib), 2.- add -L. to your 1st gcc invocation (in order to instruct gcc to look at the current directory, i.e., "."), and 3.- add -lmylib (if you called your library libmylib.a) to the gcc Your compile instruction, then, should look like gcc -o aproc aprog.c -L. -lmylib Regards. > > Anyways, thanks again. > > > Oliver > > > > > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" > -- _________________________________________________________________ Fry: You can see how I lived before I met you. Bender: You lived before you met me?! Fry: Yeah, lots of people did. Bender: Really?!
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?d825e0270911040102u40e10af7m16bc1137b48173fe>