Page 1 of 1

Cross-Compiling applications for Raspbian [solved]

Posted: Tue Mar 19, 2013 4:05 pm
by Phate
Hi!

I have setup a development platform based on Ubuntu 12.04 to cross-compile some of my applications for Raspberry Pi using Raspbian.

I used Debootstrap to get a Raspbian environment on my hostsystem. Now I can chroot with Qemu into this environment and install needed development libraries (with apt-get).

Also I downloaded the toolchain provided via Github. I set the Include-Path to /home/phate/rpi/chroot-raspbian-armhf/usr/include and the Libaray search path to /home/phate/rpi/chroot-raspbian-armhf/usr/lib. I can compile most of my applications using this setup which are also using pthread.

But one of my applications is using a library that gets installed to /usr/lib/arm-linux-gnueabihf which is /home/phate/rpi/chroot-raspbian-armhf/usr/lib/arm-linux-gnueabihf on my hostsystem. So I added this path to the library search paths. The linker can now find these libraries. But in /home/phate/rpi/chroot-raspbian-armhf/usr/lib/arm-linux-gnueabihf is also lying libpthread. Which causes the linker to fail with this error:

Code: Select all

/home/phate/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find /lib/arm-linux-gnueabihf/libpthread.so.0
/home/phate/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find /usr/lib/arm-linux-gnueabihf/libpthread_nonshared.a
collect2: error: ld returned 1 exit status
It seems the linker is searching on the hostsystem for this file: /lib/arm-linux-gnueabihf/libpthread.so.0, which is of course not available. I'm using pthread with other applications that do not use this libaray search path and it's working fine. Does somebody have tip for me? I ran out of ideas.

Thanks

Phate

Re: Cross-Compiling applications for Raspbian

Posted: Tue Mar 19, 2013 5:37 pm
by danidelrr
Hi,

I had this problem using Eclipse and Cygwin for Winodws not Ubuntu but I solved it that way.

Edit arm-unknown-linux-gnueabi\sysroot\usr\lib\libpthread.so and remove the paths in the libraries:

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 ( libpthread.so.0 libpthread_nonshared.a )
ld will now search for libpthread.so.0 and libpthread_nonshared.a in the path. Probably this libs will be on lib/arm-linux-gnueabihf not in usr/lib

Daniel

Re: Cross-Compiling applications for Raspbian

Posted: Wed Mar 20, 2013 9:46 am
by Phate
Thank you danidelrr! That did really work out that way.

For all other people who will run into a similar problem:
Just open the .so-file with an texteditor and remove the absolute paths. This needs to be done for libpthread.so and libc.so

After this there will be another problem: Some libraries use another libraries. The linker does not find these libraries. So it is also necessary to use the -rpath-link option of the linker to overwrite the runtime link path during compile time. I had to give g++ these options:

Code: Select all

-Xlinker -rpath-link=/home/phate/rpi/chroot-raspbian-armhf/usr/lib/arm-linux-gnueabihf 
-Xlinker -rpath-link=/home/phate/rpi/chroot-raspbian-armhf/lib/arm-linux-gnueabihf

Re: Cross-Compiling applications for Raspbian [solved]

Posted: Wed Mar 20, 2013 9:54 am
by danidelrr
I was meeting that "rpath" problem also in Windows with Eclipse and Cygwin.

I have tested and now it is working fine for me also. Thanks!

Daniel

Re: Cross-Compiling applications for Raspbian

Posted: Mon Jan 13, 2014 5:01 pm
by sedonami
Phate wrote:Thank you danidelrr! That did really work out that way.

For all other people who will run into a similar problem:
Just open the .so-file with an texteditor and remove the absolute paths. This needs to be done for libpthread.so and libc.so

After this there will be another problem: Some libraries use another libraries. The linker does not find these libraries. So it is also necessary to use the -rpath-link option of the linker to overwrite the runtime link path during compile time. I had to give g++ these options:

Code: Select all

-Xlinker -rpath-link=/home/phate/rpi/chroot-raspbian-armhf/usr/lib/arm-linux-gnueabihf 
-Xlinker -rpath-link=/home/phate/rpi/chroot-raspbian-armhf/lib/arm-linux-gnueabihf
I am currently having the same issue when trying to cross compile userland code with libgd. Unfortunately this suggestion doesn't work for me, as when I change the paths it complains about other files not being found. Any suggestions on how I might resolve this?

For my full issue please see: http://www.raspberrypi.org/phpBB3/viewt ... 5&p=486079

Re: Cross-Compiling applications for Raspbian [solved]

Posted: Mon Jun 15, 2015 2:42 pm
by mattc
Instead of removing the paths completely and then having to fiddle with rpath/rpath-link, you can just make these paths relative.

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/libpthread.so.0 ../../../usr/lib/arm-linux-gnueabihf/libpthread_nonshared.a )
When I did that, everything worked and I didn't need to change anything else. I'm on Xubuntu 14.04 and Raspbian 2015-05-05 release on the Pi.