How to build a simple link lib?

3 posts / 0 new
Last post
hypex
hypex's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2011-09-09 16:20
How to build a simple link lib?

Hello.

I'm trying to build a simple link lib (like simplelib.a) from a few sources but since I am inexperienced doing so I cannot figure out what flags or switches I need to add to the compiler or linker. I tried to download some sources for link libs but the Makefile gives no clue really and I tried things like -fPIC I noticed to no avail. But I am just stabbing in the dark! :-)

For those imterested I'm trying to compile ToLUA++ needed by Stratagus. It uses YABS (Yet Another Build System), this time Scons. We have Python but I can't see a Scons for OS4. In anycase I downloaded it to test but it just gave me errors. Such as: AttributeError: 'FS' object has no attribute '_cwd':

However, the instructions say, that building it just requires a few sources. Well this is fine but I've no idea how to build it all together! There is a binary that fails due to missing functions. I assume due to missing a link lib. And the link lib fails to build because it is looking for a main!

I'm sure I have built this type of thing before but now I can't for the life of me remember how to. And I bet it's damn simple. Also it would be good if we had a basic guide for this. Okay then where is this guide I failed to find? ;-)

thomas
thomas's picture
Offline
Last seen: 3 months 6 days ago
Joined: 2011-05-16 14:23
You do not need the linker.

You do not need the linker. Just create .o files from your sources and then use ar to create an archive (.a) from them.

Here is the makefile I used to compile libflac.a:

  1. SOURCES= \
  2. stream_decoder.o \
  3. bitreader.o \
  4. format.o \
  5. cpu.o \
  6. lpc.o \
  7. md5.o \
  8. memory.o \
  9. crc.o \
  10. fixed.o \
  11. bitmath.o
  12.  
  13. CC=gcc
  14. COPT=-Wall -D__USE_INLINE__ -Iinclude -I../../include -D__EMX__ -DSIZE_MAX=ULONG_MAX -DVERSION="1.2.1" -Dfseeko=fseek -Dftello=ftell
  15. LIBS=-lamiga -lauto
  16.  
  17. all: test test2
  18.  
  19. test: main.o libflac.a
  20. $(CC) $^ -o $@
  21.  
  22. test2: test2.o libflac.a
  23. $(CC) $^ -o $@ $(LIBS)
  24.  
  25. libflac.a: $(SOURCES:%.c=%.o)
  26. ar r $@ $^
  27.  
  28. .c.o:
  29. $(CC) $(COPT) -c $< -o $@
  30.  
  31. clean:
  32. -delete $(SOURCES:%.c=%.o)
  33. -delete main.o test2.o libflac.a
hypex
hypex's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2011-09-09 16:20
Thanks Thomas. Worked a

Thanks Thomas. Worked a treat. Looks like I was way off. As it is handled seperatly to the compiler and linker process. :-)

I'm using CodeBench so be good if it had a lib template. Unless I missed it.

Log in or register to post comments