Author Topic: Linking static libraries on the TI-Nspire  (Read 2955 times)

0 Members and 1 Guest are viewing this topic.

Offline hoffa

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Linking static libraries on the TI-Nspire
« on: January 25, 2012, 05:17:38 pm »
I'm porting SDL for the TI-Nspire and ran into some issues while trying to link the resulting static library. I (or rather, the Makefile) first compiled all the SDL source files into objects:

nspire-gcc -Iinclude -nostdlib -lgcc -c in.c -o out.o

It all compiles well, and then I put those objects through ar and ranlib to create a nice libSDL.a. Now when I tried to link that library with some very basic code (just in order to test at least some function is recognized):

Code: [Select]
#include "SDL.h"

int main(void) {
SDL_Init(SDL_INIT_VIDEO);
return 0;
}

Using:

nspire-gcc test.c libSDL.a -Iinclude -lc -lgcc

GCC complains:

Code: [Select]
$ nspire-gcc test.c libSDL.a -Iinclude -lc -lgcc
C:\Users\Hoffa\AppData\Local\Temp\ccSJ5EA5.o: In function `exit':
sdl.c:(.text+0x220): undefined reference to `__crt0_savedsp'
sdl.c:(.text+0x224): undefined reference to `__crt0exit'
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o): In function `exit':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\stdlib/../../../../../newlib-1.19.0/newlib/libc/stdlib/exit.c:65: undefined reference to `_exit'
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-abort.o): In function `abort':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\stdlib/../../../../../newlib-1.19.0/newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-signalr.o): In function `_kill_r':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.19.0/newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-signalr.o): In function `_getpid_r':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.19.0/newlib/libc/reent/signalr.c:96: undefined reference to `_getpid'
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.19.0/newlib/libc/reent/sbrkr.c:60: undefined reference to `_sbrk'
collect2: ld returned 1 exit status

If I do not link it with libc/newlib (which would actually be better as far as I can see), it would complain about undefined references to memset(). (something warned about in the GCC man pages)
If any of you know how to deal with this issue, it would help me quite a lot; I could start testing some real code.

Edit:
This is the output when compiling without newlib (i.e., -nostdlib instead of -lc):

Code: [Select]
$ nspire-gcc test.c libSDL.a -Iinclude -nostdlib -lgcc
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/bin/ld.exe: warning: cannot find entry symbol _start; defaulting to 00008000
C:\Users\Hoffa\AppData\Local\Temp\ccqMjuGx.o: In function `exit':
sdl.c:(.text+0x220): undefined reference to `__crt0_savedsp'
sdl.c:(.text+0x224): undefined reference to `__crt0exit'
libSDL.a(SDL_cursor.o): In function `SDL_MouseRect':
SDL_cursor.c:(.text+0x164): undefined reference to `memcpy'
libSDL.a(SDL_keyboard.o): In function `SDL_PrivateKeyboard':
SDL_keyboard.c:(.text+0x390): undefined reference to `memcpy'
libSDL.a(SDL_surface.o): In function `SDL_GetClipRect':
SDL_surface.c:(.text+0x34c): undefined reference to `memcpy'
libSDL.a(SDL_surface.o): In function `SDL_LowerBlit':
SDL_surface.c:(.text+0x3e8): undefined reference to `memcpy'
SDL_surface.c:(.text+0x424): undefined reference to `memcpy'
libSDL.a(SDL_surface.o):SDL_surface.c:(.text+0x838): more undefined references to `memcpy' follow
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2\libgcc.a(unwind-arm.o): In function `unwind_phase2':
C:\msys\1.0\home\yagarto\gcc-build\arm-none-eabi\libgcc/../../../gcc-4.6.2/libgcc/../gcc/config/arm/unwind-arm.c:698: undefined reference to `abort'
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2\libgcc.a(unwind-arm.o): In function `__gnu_Unwind_Resume':
C:\msys\1.0\home\yagarto\gcc-build\arm-none-eabi\libgcc/../../../gcc-4.6.2/libgcc/../gcc/config/arm/unwind-arm.c:885: undefined reference to `abort'
C:\msys\1.0\home\yagarto\gcc-build\arm-none-eabi\libgcc/../../../gcc-4.6.2/libgcc/../gcc/config/arm/unwind-arm.c:903: undefined reference to `abort'
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2\libgcc.a(pr-support.o): In function `_Unwind_GetDataRelBase':
C:\msys\1.0\home\yagarto\gcc-build\arm-none-eabi\libgcc/../../../gcc-4.6.2/libgcc/../gcc/config/arm/pr-support.c:394: undefined reference to `abort'
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2\libgcc.a(pr-support.o): In function `_Unwind_GetTextRelBase':
C:\msys\1.0\home\yagarto\gcc-build\arm-none-eabi\libgcc/../../../gcc-4.6.2/libgcc/../gcc/config/arm/pr-support.c:400: undefined reference to `abort'
collect2: ld returned 1 exit status
« Last Edit: January 26, 2012, 01:49:50 pm by hoffa »

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: Linking static libraries on the TI-Nspire
« Reply #1 on: January 26, 2012, 12:42:34 pm »
"nspire-gcc test.c libSDL.a -Iinclude -lc -lgcc"

Could you try instead:
nspire-gcc -c test.c -Iinclude
nspire-ld test.o -lSDL
Ndless.me with the finest TI-Nspire programs

Offline hoffa

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: Linking static libraries on the TI-Nspire
« Reply #2 on: January 26, 2012, 01:11:27 pm »
Output:
Code: [Select]
$ nspire-ld sdl.o libSDL.a
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2\libgcc.a(unwind-arm.o): In function `get_eit_entry':
C:\msys\1.0\home\yagarto\gcc-build\arm-none-eabi\libgcc/../../../gcc-4.6.2/libgcc/../gcc/config/arm/unwind-arm.c:614: undefined reference to `__exidx_start'
C:\msys\1.0\home\yagarto\gcc-build\arm-none-eabi\libgcc/../../../gcc-4.6.2/libgcc/../gcc/config/arm/unwind-arm.c:614: undefined reference to `__exidx_end'
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-abort.o): In function `abort':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\stdlib/../../../../../newlib-1.19.0/newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-signalr.o): In function `_kill_r':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.19.0/newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-signalr.o): In function `_getpid_r':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.19.0/newlib/libc/reent/signalr.c:96: undefined reference to `_getpid'
collect2: ld returned 1 exit status

Seems like some ARM specific errors. Doesn't seem to recognize the entry point.

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: Linking static libraries on the TI-Nspire
« Reply #3 on: January 26, 2012, 04:17:08 pm »
Here is an update of the Ndless SDK for you that should fix this (r526):
- Add _TINSPIRE
- Add missing syscalls stub for newlib
Ndless.me with the finest TI-Nspire programs

Offline hoffa

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 322
  • Rating: +131/-13
    • View Profile
Re: Linking static libraries on the TI-Nspire
« Reply #4 on: January 26, 2012, 05:13:12 pm »
Here is an update of the Ndless SDK for you that should fix this (r526):
- Add _TINSPIRE
- Add missing syscalls stub for newlib
Wonderful, that fixed it, thanks a lot! Now I'll be able to get to the real thing.

Edit:
The TNS is not accepted by nspire_emu (i.e., nothing shows up), but I'll look into that tomorrow.

Edit 2:

Compiling:
Code: [Select]
#include <os.h>

int main(void) {
puts("Hello!");
return 0;
}

Using: nspire-gcc test.c -nostdlib

Gives:
Code: [Select]
$ nspire-gcc -nostdlib sdl.c
c:/program files (x86)/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/bin/ld.exe: warning: cannot find entry symbol _start; defaulting to 00008000
C:\Users\Hoffa\AppData\Local\Temp\ccKOUO0B.o: In function `exit':
sdl.c:(.text+0x250): undefined reference to `__crt0_savedsp'
sdl.c:(.text+0x254): undefined reference to `__crt0exit'
collect2: ld returned 1 exit status

Edit 3:
Seems to compile and run today, never mind. When it comes to SDL, still haven't managed to call a function. I'm looking into that now.
« Last Edit: January 27, 2012, 07:03:44 am by hoffa »

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: Linking static libraries on the TI-Nspire
« Reply #5 on: January 28, 2012, 03:17:57 am »
Make always sure to use "nspire-gcc -c" to compile, and "nspire-ld" separately to link to avoid your initial error.
« Last Edit: January 28, 2012, 03:18:14 am by ExtendeD »
Ndless.me with the finest TI-Nspire programs