Acorn Arcade forums: Programming: how to compile a library object?
|
how to compile a library object? |
|
instantiator (20:52 18/7/2005) jmb (23:18 18/7/2005) instantiator (11:06 19/7/2005) instantiator (14:52 20/7/2005)
|
|
Lewis Westbury |
Message #67797, posted by instantiator at 20:52, 18/7/2005 |
Member
Posts: 365
|
Hi there,
I'm having problems compiling a library object for linking to. I've got a whole bunch of sources and headers, and they compile together fine to make an application; but I can't work out what I need to do to get gcc to overlook the absence of main() and compile them into a library object...
Any suggestions? |
|
[ Log in to reply ] |
|
JMB |
Message #67813, posted by jmb at 23:18, 18/7/2005, in reply to message #67797 |
Member
Posts: 467
|
Hi there,
I'm having problems compiling a library object for linking to. I've got a whole bunch of sources and headers, and they compile together fine to make an application; but I can't work out what I need to do to get gcc to overlook the absence of main() and compile them into a library object...
Any suggestions? Create a makefile, thus:
# our tools CC=gcc CFLAGS= AR=ar ARFLAGS=-cru
# Stick the object names here - they should be unique OBJECTS = foo.o foo1.o foo2.o
# our target - note that the spaces at the start of the # "$(AR) ..." line should actually be a tab character # $@ gets substituted with the name of the target (i.e. mylibrary) # $^ gets substituted by the contents of $(OBJECTS) mylibrary: $(OBJECTS) $(AR) $(ARFLAGS) $@ $^
# pattern rule for compiling foo.c into foo.o # again, the spaces before "$(CC)..." should be a tab character # $< will get substituted with the name of the source file that's # being compiled at the time %.o: %.c $(CC) -c -o $@ $<
and invoke make on it, thus:
make mylibrary
[you can omit the mylibrary bit, if you like, as it's the only target present in the makefile so will get executed by default] |
|
[ Log in to reply ] |
|
Lewis Westbury |
Message #67822, posted by instantiator at 11:06, 19/7/2005, in reply to message #67813 |
Member
Posts: 365
|
thanks didn't realise I'd need AR i'll take a look tonight |
|
[ Log in to reply ] |
|
Lewis Westbury |
Message #67848, posted by instantiator at 14:52, 20/7/2005, in reply to message #67822 |
Member
Posts: 365
|
thanks!!! |
|
[ Log in to reply ] |
|
|
Acorn Arcade forums: Programming: how to compile a library object? |