Vanfanel
Posts: 443
Joined: Sat Aug 18, 2012 5:58 pm

Cross compiling a simple program that uses an installed lib

Tue Oct 13, 2015 12:53 pm

Hi there,

I'm having seemingly unsolvable problems while trying to cross compile a simple Rpi program on my X86 box. It was working before but I've since rebuilt my system and now I can't make it work anymore.

I am using a cross-compiler I built using crosstool-ng. It lives on ~/x-tools/arm-rpi-linux-gnueabi, I have added the executables to the PATH and it has it's own sysroot on ~/x-tools/arm-rpi-linux-gnueabi/arm-rpi-linux-gnueabi/sysroot. It works in general for generating simple binaries that work on the Pi.

I also have copied over /usr /lib and /opt from the Raspberry Pi's Raspbian SD card to /opt/rpi_root, so I have another sysroot living there in /opt/rpi_root, which has the libraries installed in Raspbian.

Crosscompiling a simple program with no libs or references to the Raspbian sysroot works well:

Code: Select all

arm-rpi-linux-gnueabi-gcc hello.c
and the resulting binary works on the Pi.

The problems start when I try to link against libs installed in Raspbian:

Code: Select all

manuel@vader:~/src/picross$ arm-rpi-linux-gnueabi-gcc hello.c -lSDL
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: cannot find -lSDL
collect2: error: ld returned 1 exit status
Obviously it's looking for a library that is installed in Raspbian, so I do:

Code: Select all

manuel@vader:~/src/picross$ find /opt/rpi_root -name 'libSDL.so'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so
Ok, found it. So I try:

Code: Select all

manuel@vader:~/src/picross$ arm-rpi-linux-gnueabi-gcc hello.c -lSDL -L/opt/rpi_root/usr/lib/arm-linux-gnueabihf
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: cannot find /lib/arm-linux-gnueabihf/libc.so.6
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: cannot find /usr/lib/arm-linux-gnueabihf/libc_nonshared.a
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: cannot find /lib/arm-linux-gnueabihf/ld-linux-armhf.so.3
collect2: error: ld returned 1 exit status
Ok, so the problem is that libc.so in the crosscompiler sysroot has wrong paths for libc.so.6, libc_nonshared.a and ld-linux-armhf.so.3 because it's using absolute paths. Let's see what we have in /home/manuel/x-tools/arm-rpi-linux-gnueabi/arm-rpi-linux-gnueabi/sysroot/usr/lib/libc.so:

Code: Select all

/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */  
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a  AS_NEEDED ( /lib/ld-linux.so.3 ) )
Bingo! So what are the alternatives? I could start editing the crosscompiler's sysroot ld scripts for every library, which is just crazy, or I could change my strategy and try passing the compiler a new sysroot so it ONLY takes ld scripts and libs from the Raspbian sysroot living in /opt/rpi_root:

Code: Select all

manuel@vader:~/src/picross$ arm-rpi-linux-gnueabi-gcc hello.c --sysroot=/opt/rpi_root -lSDL 
In file included from /opt/rpi_root/usr/include/stdio.h:28:0,
                 from hello.c:2:
/opt/rpi_root/usr/include/features.h:323:26: fatal error: bits/predefs.h: No such file or directory
compilation terminated.
Oh, we also need to tell the compiler where it has to look for certain includes:

Code: Select all

manuel@vader:~/src/picross$ arm-rpi-linux-gnueabi-gcc hello.c --sysroot=/opt/rpi_root -lSDL -I/opt/rpi_root/usr/include/arm-linux-gnueabihf
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: cannot find crt1.o: No such file or directory
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: cannot find crti.o: No such file or directory
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: cannot find -lSDL
collect2: error: ld returned 1 exit status
Well, around here I get confused and desperated. Cannot find -lSDL on the Raspbian sysroot living on /opt/rpi_root? Ok... it shouldn't happen, but ok:

Code: Select all

manuel@vader:~/src/picross$ find /opt/rpi_root -name 'libSDL.so'/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so
manuel@vader:~/src/picross$ arm-rpi-linux-gnueabi-gcc hello.c --sysroot=/opt/rpi_root -lSDL -I/opt/rpi_root/usr/include/arm-linux-gnueabihf -L/opt/rpi_root/usr/lib/arm-linux-gnueabihf 
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: cannot find crt1.o: No such file or directory
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status
Ok, ok, don't panic, let's try adding the -B parameter to pass the binary objects location it's looking for. It makes no sense and means --sysroot=/opt/rpi_root isn't working as intended.

Code: Select all

manuel@vader:~/src/picross$ find /opt/rpi_root -name 'crt1.o'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/crt1.o
manuel@vader:~/src/picross$ arm-rpi-linux-gnueabi-gcc hello.c --sysroot=/opt/rpi_root -lSDL -I/opt/rpi_root/usr/include/arm-linux-gnueabihf -L/opt/rpi_root/usr/lib/arm-linux-gnueabihf -B /opt/rpi_root/usr/lib/arm-linux-gnueabihf
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libasound.so.2, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libm.so.6, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libdl.so.2, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libpulse-simple.so.0, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libpulse.so.0, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libX11.so.6, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libXext.so.6, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libbcm_host.so, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libvcos.so, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libvchiq_arm.so, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libdirectfb-1.2.so.9, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libfusion-1.2.so.9, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libdirect-1.2.so.9, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libcaca.so.0, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libts-0.0.so.0, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: warning: libpthread.so.0, needed by /opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so, not found (try using -rpath or -rpath-link)
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XAllocClassHint'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSendEvent'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XReparentWindow'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `_XFlush'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pthread_mutexattr_init@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_stream_drain@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XFreeModifiermap'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetTransientForHint'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pow@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_stream_connect_playback@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_sizeof@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XESetEventToWire'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetIOErrorHandler'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XClearWindow'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_display_get_info'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_resource_delete'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `__caca0_free_bitmap'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_copy@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XFreeColormap'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XAllocColor'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_nonblock@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_set_access@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XResizeWindow'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `log@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XLookupString'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetExtensionErrorHandler'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_rect_set'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_simple_new@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XGetICValues'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XResetScreenSaver'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XESetWireToEvent'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XChangePointerControl'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_context_connect@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_sw_params_set_start_threshold@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_context_disconnect@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XEventsQueued'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XOpenIM'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `_XReply'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XPending'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_set_periods_near@ALSA_0.9.0rc4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `__caca0_create_bitmap'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `ts_fd'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XListPixmapFormats'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_stream_new@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XIconifyWindow'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XextFindDisplay'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_recover@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_set_period_size_near@ALSA_0.9.0rc4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_element_add'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XCreatePixmapFromBitmapData'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `DirectFBErrorString'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XFreeColors'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `DirectFBCreate'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `ts_config'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XFree'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `_XSend'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XextRemoveDisplay'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XMoveWindow'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `caca_refresh_display'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XDeleteProperty'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XMoveResizeWindow'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `caca_get_canvas_height'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pthread_create@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_any@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XFreePixmap'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XShmQueryExtension'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `__caca0_end'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `sem_getvalue@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetWMHints'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XPeekEvent'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XGetVisualInfo'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XChangeWindowAttributes'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetWMNormalHints'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XGrabPointer'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_set_format@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XDestroyIC'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_sw_params@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XCreatePixmapCursor'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XWarpPointer'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XextDestroyExtension'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_resource_create'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_sw_params_set_avail_min@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_set_channels@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_operation_cancel@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `dlsym@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `Xutf8TextListToTextProperty'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_close@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_get_periods@ALSA_0.9.0rc4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_get_channels@ALSA_0.9.0rc4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `__caca0_get_event'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XDestroyWindow'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_element_change_source'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_stream_write@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XGetErrorDatabaseText'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XShmPutImage'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `__caca0_dp'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_context_unref@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XCreateIC'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XVisualIDFromVisual'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `caca_dither_bitmap'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_set_rate_near@ALSA_0.9.0rc4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XOpenDisplay'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pthread_cancel@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_operation_unref@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_operation_get_state@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XStringListToTextProperty'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XGetModifierMapping'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_stream_writable_size@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `bcm_host_init'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XMissingExtension'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_mainloop_free@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetWMProtocols'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `sem_timedwait@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XQueryPointer'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XKeysymToKeycode'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XShmDetach'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XUngrabPointer'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `ts_read'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_mainloop_iterate@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XCloseIM'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_set_buffer_size_near@ALSA_0.9.0rc4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XAllocSizeHints'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `sem_init@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetErrorHandler'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_element_remove'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XQueryExtension'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `_XGetRequest'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XAllocWMHints'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_stream_unref@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XQueryColors'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `sem_wait@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pthread_sigmask@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XNextEvent'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_stream_disconnect@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XMapRaised'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XInternAtom'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XQueryKeymap'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_stream_get_state@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XChangeProperty'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XDisplayName'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetLocaleModifiers'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `__caca0_init'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_display_open'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XCreateWindow'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XRefreshKeyboardMapping'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSync'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSelectInput'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetClassHint'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_context_get_state@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `_XRead'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_sw_params_current@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_update_start'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XDefineCursor'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_writei@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `ts_open'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XCreateGC'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XUnmapWindow'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XUnsetICFocus'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XCreateSimpleWindow'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_resource_set_palette'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `_XSetLastRequestRead'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_context_set_name@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XKeycodeToKeysym'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_get_buffer_size@ALSA_0.9.0rc4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_hw_params_get_period_size@ALSA_0.9.0rc4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `__caca0_cv'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XFlush'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XextCreateExtension'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XCreateColormap'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XGetPointerControl'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XGetWindowAttributes'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pthread_join@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetICFocus'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_simple_free@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `caca_get_canvas_width'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XPutImage'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `_XReadPad'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_mainloop_get_api@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XMatchVisualInfo'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetWindowColormap'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetWindowBackgroundPixmap'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XCheckTypedEvent'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `_XEatData'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XFreeCursor'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_sw_params_sizeof@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XMapWindow'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_channel_map_init_auto@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `sem_destroy@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `Xutf8LookupString'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetWindowBackground'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_open@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XSetTextProperty'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XFreeGC'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pthread_mutexattr_settype@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `_XFlushGCCache'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `DirectFBError'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XShmAttach'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `dlerror@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XGetWMHints'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XextAddDisplay'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_strerror@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XShmCreateImage'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XUngrabKeyboard'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XFilterEvent'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `dlopen@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `ts_close'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_mainloop_new@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `sem_trywait@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XInstallColormap'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XStoreColors'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XRaiseWindow'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XCloseDisplay'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XCreateImage'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XCreatePixmap'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `snd_pcm_drain@ALSA_0.9'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_display_close'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `pa_context_new@PULSE_0'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `dlclose@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `DirectFBInit'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XDisplayOfIM'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XMaskEvent'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_update_submit_sync'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `vc_dispmanx_resource_write_data'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `sem_post@GLIBC_2.4'
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libSDL.so: undefined reference to `XGrabKeyboard'
collect2: error: ld returned 1 exit status
After this I close my eyes, breathe deeply not to throw my laptop away across the closed window, and come here for help.
What am I doing wrong?? Passing --sysroot should DO it, the compiler and linker should find and use the ld scripts and libs and headers from /opt/sysroot, but according to

Code: Select all

manuel@vader:~/src/picross$ arm-rpi-linux-gnueabi-gcc hello.c --sysroot=/opt/rpi_root -lSDL -I/opt/rpi_root/usr/include/arm-linux-gnueabihf -v
Using built-in specs.
COLLECT_GCC=arm-rpi-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/home/manuel/x-tools/arm-rpi-linux-gnueabi/libexec/gcc/arm-rpi-linux-gnueabi/4.7.4/lto-wrapper
Target: arm-rpi-linux-gnueabi
Configured with: /home/manuel/cross-rasp/.build/src/gcc-linaro-4.7-2014.01/configure --build=x86_64-build_unknown-linux-gnu --host=x86_64-build_unknown-linux-gnu --target=arm-rpi-linux-gnueabi --prefix=/home/manuel/x-tools/arm-rpi-linux-gnueabi --with-sysroot=/home/manuel/x-tools/arm-rpi-linux-gnueabi/arm-rpi-linux-gnueabi/sysroot --enable-languages=c,c++ --with-arch=armv6zk --with-cpu=arm1176jzf-s --with-tune=arm1176jzf-s --with-fpu=vfp --with-float=hard --with-pkgversion='crosstool-NG 1.20.0' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --with-gmp=/home/manuel/cross-rasp/.build/arm-rpi-linux-gnueabi/buildtools --with-mpfr=/home/manuel/cross-rasp/.build/arm-rpi-linux-gnueabi/buildtools --with-mpc=/home/manuel/cross-rasp/.build/arm-rpi-linux-gnueabi/buildtools --with-ppl=/home/manuel/cross-rasp/.build/arm-rpi-linux-gnueabi/buildtools --with-cloog=/home/manuel/cross-rasp/.build/arm-rpi-linux-gnueabi/buildtools --with-libelf=/home/manuel/cross-rasp/.build/arm-rpi-linux-gnueabi/buildtools --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm -L/home/manuel/cross-rasp/.build/arm-rpi-linux-gnueabi/buildtools/lib -lpwl' --enable-threads=posix --enable-target-optspace --disable-nls --disable-multilib --with-local-prefix=/home/manuel/x-tools/arm-rpi-linux-gnueabi/arm-rpi-linux-gnueabi/sysroot --enable-c99 --enable-long-long --with-float=hard
Thread model: posix
gcc version 4.7.4 20140107 (prerelease) (crosstool-NG 1.20.0) 
COLLECT_GCC_OPTIONS='-I' '/opt/rpi_root/usr/include/arm-linux-gnueabihf' '-v' '-march=armv6zk' '-mtune=arm1176jzf-s' '-mfloat-abi=hard' '-mfpu=vfp' '-mtls-dialect=gnu'
 /home/manuel/x-tools/arm-rpi-linux-gnueabi/libexec/gcc/arm-rpi-linux-gnueabi/4.7.4/cc1 -quiet -v -I /opt/rpi_root/usr/include/arm-linux-gnueabihf -isysroot /opt/rpi_root hello.c -quiet -dumpbase hello.c -march=armv6zk -mtune=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp -mtls-dialect=gnu -auxbase hello -version -o /tmp/ccBXrCwp.s
GNU C (crosstool-NG 1.20.0) version 4.7.4 20140107 (prerelease) (arm-rpi-linux-gnueabi)
	compiled by GNU C version 4.9.2, GMP version 5.1.3, MPFR version 3.1.2, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/opt/rpi_root/home/manuel/x-tools/arm-rpi-linux-gnueabi/arm-rpi-linux-gnueabi/sysroot/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/rpi_root/usr/include/arm-linux-gnueabihf
 /home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/include
 /home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/include-fixed
 /home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/include
 /opt/rpi_root/usr/include
End of search list.
GNU C (crosstool-NG 1.20.0) version 4.7.4 20140107 (prerelease) (arm-rpi-linux-gnueabi)
	compiled by GNU C version 4.9.2, GMP version 5.1.3, MPFR version 3.1.2, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ef439bbfaf97ced736f40e5e67b965df
COLLECT_GCC_OPTIONS='-I' '/opt/rpi_root/usr/include/arm-linux-gnueabihf' '-v' '-march=armv6zk' '-mtune=arm1176jzf-s' '-mfloat-abi=hard' '-mfpu=vfp' '-mtls-dialect=gnu'
 /home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/as -v -I /opt/rpi_root/usr/include/arm-linux-gnueabihf -march=armv6zk -mfloat-abi=hard -mfpu=vfp -meabi=5 -o /tmp/cckIn07q.o /tmp/ccBXrCwp.s
GNU assembler version 2.24 (arm-rpi-linux-gnueabi) using BFD version (crosstool-NG 1.20.0) 2.24
COMPILER_PATH=/home/manuel/x-tools/arm-rpi-linux-gnueabi/libexec/gcc/arm-rpi-linux-gnueabi/4.7.4/:/home/manuel/x-tools/arm-rpi-linux-gnueabi/libexec/gcc/arm-rpi-linux-gnueabi/4.7.4/:/home/manuel/x-tools/arm-rpi-linux-gnueabi/libexec/gcc/arm-rpi-linux-gnueabi/:/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/:/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/:/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/
LIBRARY_PATH=/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/:/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/lib/:/opt/rpi_root/lib/:/opt/rpi_root/usr/lib/
COLLECT_GCC_OPTIONS='-I' '/opt/rpi_root/usr/include/arm-linux-gnueabihf' '-v' '-march=armv6zk' '-mtune=arm1176jzf-s' '-mfloat-abi=hard' '-mfpu=vfp' '-mtls-dialect=gnu'
 /home/manuel/x-tools/arm-rpi-linux-gnueabi/libexec/gcc/arm-rpi-linux-gnueabi/4.7.4/collect2 --sysroot=/opt/rpi_root --eh-frame-hdr -dynamic-linker /lib/ld-linux-armhf.so.3 -X -m armelf_linux_eabi crt1.o crti.o /home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/crtbegin.o -L/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4 -L/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/lib -L/opt/rpi_root/lib -L/opt/rpi_root/usr/lib /tmp/cckIn07q.o -lSDL -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/crtend.o crtn.o
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: cannot find crt1.o: No such file or directory
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: cannot find crti.o: No such file or directory
/home/manuel/x-tools/arm-rpi-linux-gnueabi/lib/gcc/arm-rpi-linux-gnueabi/4.7.4/../../../../arm-rpi-linux-gnueabi/bin/ld: cannot find -lSDL
collect2: error: ld returned 1 exit status
it's using a mixture of both /opt/rpi_root sysroot and the ~/x-tools/arm-rpi-linux-gnueabi/arm-rpi-linux-gnueabi/sysroot sysroot.
Please help me here :oops:

Vanfanel
Posts: 443
Joined: Sat Aug 18, 2012 5:58 pm

Re: Cross compiling a simple program that uses an installed

Tue Oct 13, 2015 5:43 pm

I managed to cross-compile by editing
/opt/rpi_root/usr/lib/arm-linux-gnueabihf/libc.so

and setting the paths to relative ones, leaving it like this:

Code: Select all

/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */  
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( ../../../lib/arm-linux-gnueabihf/libc.so.6 ../../../usr/lib/arm-linux-gnueabihf/libc_nonshared.a  AS_NEEDED ( ../../../lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 ) )
then I did:

Code: Select all

manuel@vader:~/src/picross$ arm-rpi-linux-gnueabi-gcc hello.c -lSDL -L /opt/rpi_root/usr/lib/arm-linux-gnueabihf -I/opt/rpi_root/usr/include/arm-linux-gnueabihf -Xlinker -rpath-link=/opt/rpi_root/usr/lib/arm-linux-gnueabihf -Xlinker -rpath-link=/opt/rpi_root/lib/arm-linux-gnueabihf -Xlinker -rpath-link=/opt/rpi_root/opt/vc/lib -Xlinker -rpath-link=/opt/rpi_root/usr/lib/arm-linux-gnueabihf/pulseaudio
But this seems overkilling to me.
Isn't it possible to simply pass --sysroot instead to the linker and NOT havng to fiddle with .so editing on the Raspbian sysroot nor rpath-link parameters??

Vanfanel
Posts: 443
Joined: Sat Aug 18, 2012 5:58 pm

Re: Cross compiling a simple program that uses an installed

Fri Oct 16, 2015 10:46 am

The sysroot parameter works right. That's not the problem of all this mess.
The root cause of all this is since Wheezy (on which Raspbian is/was based), Debian adds "multiarch". That means that LD scripts, headers and actual libs can be in the sysroot for different achitectures at the same time.
Old Raspbian (whatever I was using before) had all libs/includes/LD scripts under "standard" locations like /usr/lib, /lib, /usr/include... but now, some of them are under routes like /usr/lib/arm-linux-gnueabihf, /lib/arm-linux-gnueabihf, /usr/include/arm-linux-gnueabihf...
To make the crosscompiler look into the "arm-linux-gnueabihf" subdirs we should build it with the "--enable-multiarch --target=arm-linux-gnueabihf" options. That will also make linker look for the crt*.o files in <sysroot>/usr/lib/arm-linux-gnueabihf instead of <sysroot>/usr/lib.
BUT since there's no support for multiarch in crosstool-ng that I can see, there's no way to use it to build a crosscompiler for a modern Raspbian system that has multiarch.
The only option I am left with is manuallt putting whatever is needed from the arm-linux-gnueabihf subdirs to "standard" non-multiarch locations, fixing paths in .so LD scripts, etc... what a mess.

User avatar
yasriady
Posts: 27
Joined: Wed Apr 08, 2015 2:37 am
Location: Indonesia
Contact: Website

Re: Cross compiling a simple program that uses an installed

Mon Oct 19, 2015 3:29 am

Dear there,
I use buildroot build system to generate my own toolchain. Shall you want to try, please use the way I'm followed: http://yasriady.blogspot.co.id/2015/10/ ... ry-pi.html. Buildroot is very nice because it can automate to build dependency library such X11, GTK, and other related. So, please make a try and good luck.
MyRaspberryPi : Cross Compile, wxWidgets/C++ and Linux Journal at http://yasriady.blogspot.com

vagrant4ever
Posts: 3
Joined: Thu Apr 21, 2016 9:17 pm

Re: Cross compiling a simple program that uses an installed

Thu Apr 21, 2016 10:21 pm

I believe I am running into the same multiarch problem. I am porting an application that uses several libraries (bluetooth, log4cxx, etc) to the Rpi3 (Jessie, gcc 4.9.3). My host system is Ubuntu 14.04 (gcc 4.9.3)

I "rsync"ed /usr and /lib from my RPi3 to:

Code: Select all

~/raspberrypi/rootfs
I am using this as my sysroot.

I downloaded the pre-built toolchains from:

Code: Select all

git clone https://github.com/raspberrypi/tools
I first attempted to use this tool chain:

Code: Select all

~/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
This one supported multiarch:

Code: Select all

./arm-linux-gnueabihf-gcc --print-multiarch
arm-linux-gnueabihf
However the compiler version is 4.8.3, and I received link errors:

Code: Select all

/home/steve/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/liblog4cxx.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'
collect2: error: ld returned 1 exit status
make: *** [MasterPi] Error 1
A google search turned up that libs may be compiled with different compiler versions.

I then tried this toolchain:

Code: Select all

~/raspberrypi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin
This one does not support multiarch:

Code: Select all

steve@steve-HP-EliteBook-8570w:~/raspberrypi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin$ ./arm-linux-gnueabihf-gcc --print-multiarch

steve@steve-HP-EliteBook-8570w:~/raspberrypi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin$ 
And I receive the following link errors:

Code: Select all

/home/steve/raspberrypi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find crt1.o: No such file or directory
/home/steve/raspberrypi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find crti.o: No such file or directory
/home/steve/raspberrypi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -llog4cxx
/home/steve/raspberrypi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lpthread
/home/steve/raspberrypi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lbluetooth
/home/steve/raspberrypi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lglib-2.0
/home/steve/raspberrypi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lssl
/home/steve/raspberrypi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lcrypto
/home/steve/raspberrypi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lm
collect2: error: ld returned 1 exit status
make: *** [MasterPi] Error 1
I even tried to build a toolchain with crosstool-ng and still ran into linking issues. More research and it looks like crosstool-ng does not support multiarch....

Any help would be greatly appreciated! Surely there is a toolchain out there some where :oops:

Thanks

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: Cross compiling a simple program that uses an installed

Fri Apr 22, 2016 9:20 am

is there a special reason why you want to cross-compile and not just compile on the Pi itself, plugging a keyboard, a mouse, and a HDMI-Monitor (or a DVI Monitor plus a HDMI Adapter) ?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

jahboater
Posts: 5691
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Cross compiling a simple program that uses an installed

Fri Apr 22, 2016 11:27 am

davenull wrote:is there a special reason why you want to cross-compile and not just compile on the Pi itself, plugging a keyboard, a mouse, and a HDMI-Monitor (or a DVI Monitor plus a HDMI Adapter) ?
Yes!
Have you tried a Pi3? Its pretty fast, and capable of building almost anything (such as the Linux kernel or GCC itself).
You can of course ssh into the Pi to build things.
Pi4 8GB running PIOS64

vagrant4ever
Posts: 3
Joined: Thu Apr 21, 2016 9:17 pm

Re: Cross compiling a simple program that uses an installed

Mon Apr 25, 2016 4:59 pm

Yes, that is an option. However I cross compile this code for multiple boards (intel Edison, etc) and I was hoping to find a toolchain that would allow me to do so for the Pi 3.

Return to “C/C++”