Author Topic: How can I use a static library?  (Read 4468 times)

0 Members and 1 Guest are viewing this topic.

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
How can I use a static library?
« on: August 30, 2012, 04:53:05 pm »
I'm trying to use fdlibm which hoffa ported, but I get
Code: [Select]
nspire-ld -L ../../../.ndless/lib -lfdm sound.o output.o -o sound.elf
sound.o: In function `playKey':
sound.c:(.text+0xc4): undefined reference to `pow'
collect2.exe: error: ld returned 1 exit status
make: *** [sound.tns] Error 1

with
GCCFLAGS = -I ../../../.ndless/include -Os -Wall -W
LDFLAGS = -L ../../../.ndless/lib -lfdm

What am I doing wrong?

Offline hoffa

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 304
  • Rating: +131/-13
    • View Profile
Re: How can I use a static library?
« Reply #1 on: September 06, 2012, 11:27:46 am »
Just copy the files in the archive to your .ndless folder, and using the sample Makefile included with nSDL add -lfdm to the LIBS line (i.e. LIBS = -lSDL -lfdm). With a simple make it should then compile fine.

Oh and there's no need to use -I or -L if the .ndless folder is in your home (whatever it is on your OS).

EDIT: Didn't notice there was no nSDL involved. Download fdlibm here, do what I said up there, and use this as your Makefile which should make it work (just adapt it for you of course):
Code: [Select]
SOURCES = test.c
TARGET = Test.tns
OBJECTS = $(SOURCES:.c=.o)

CC = nspire-gcc
LD = nspire-ld
OBJCOPY = arm-none-eabi-objcopy
CFLAGS = -Wall -Wextra -Ofast
LDFLAGS =
LIBS = -lfdm

all: $(TARGET)

$(TARGET): $(OBJECTS)
$(LD) $(LDFLAGS) $^ $(LIBS) -o $(@:.tns=.elf)
$(OBJCOPY) -O binary $(@:.tns=.elf) $(TARGET)

.c.o:
$(CC) $(CFLAGS) -c $< -o $@

clean:
rm -f $(OBJECTS) $(TARGET:.tns=.elf) $(TARGET)
« Last Edit: September 06, 2012, 11:34:46 am by hoffa »

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: How can I use a static library?
« Reply #2 on: September 06, 2012, 11:35:14 am »
Thanks, it compiles  :thumbsup: