log in | register | forums
Show:
Go:
Forums
Username:

Password:

User accounts
Register new account
Forgot password
Forum stats
List of members
Search the forums

Advanced search
Recent discussions
- Elsear brings super-fast Networking to Risc PC/A7000/A7000+ (News:)
- Latest hardware upgrade from RISCOSbits (News:)
- Accessing old floppy disks (Gen:3)
- November developer 'fireside' chat on saturday night (News:)
- RISCOSbits releases a new laptop solution (News:4)
- Announcing the TIB 2024 Advent Calendar (News:2)
- RISC OS London Show Report 2024 (News:1)
- Code GCC produces that makes you cry #12684 (Prog:39)
- Rougol November 2024 meeting on monday (News:)
- Drag'n'Drop 14i1 edition reviewed (News:)
Latest postings RSS Feeds
RSS 2.0 | 1.0 | 0.9
Atom 0.3
Misc RDF | CDF
 
View on Mastodon
@www.iconbar.com@rss-parrot.net
Site Search
 
Article archives
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!!! :D
  ^[ Log in to reply ]
 

Acorn Arcade forums: Programming: how to compile a library object?