compiling c lib

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
GLneo

compiling c lib

Post 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
Ushma

Re:compiling c lib

Post by Ushma »

Use the -c flag.
GLneo

Re:compiling c lib

Post by GLneo »

thx, *smack my self in head*, thx
cabron

Re:compiling c lib

Post 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.
Post Reply