Page 1 of 1

compiling c lib

Posted: Thu Jul 28, 2005 8:55 pm
by GLneo
hi all, i have files with functions for my lib but i dont know how to compile them to ".o", i've tried:

Code: Select all

gcc stdio.c -o stdio.o
but it says something like:
djgpp/lib/crt0.o:undefined reference to '_main'
djgpp/lib/libc.a:undefined reference to '_main'
???, thx

Re:compiling c lib

Posted: Thu Jul 28, 2005 10:21 pm
by Ushma
Use the -c flag.

Re:compiling c lib

Posted: Fri Jul 29, 2005 8:12 am
by GLneo
thx, *smack my self in head*, thx

Re:compiling c lib

Posted: Fri Jul 29, 2005 9:40 am
by cabron
If you're making a library you might also want to look at the "ar" program. It makes the *.a files.

For example, let's say you had objects called stdio.o and foo.o, you can make libstdio.a with:

ar cq libstdio.a stdio.o foo.o

Note: if libstdio.a already exists you may have to remove it. In my Makefiles I always do an rm -f before an ar, but it looks like you're using DOS/DJGPP, so I guess it would be the DEL command for you.

Then you can link your user programs with:

ld whatever whatever -lstdio

Provided the libstdio.a is in the right place.