Phate
Posts: 5
Joined: Tue Mar 19, 2013 3:49 pm

Cross-Compiling applications for Raspbian [solved]

Tue Mar 19, 2013 4:05 pm

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
Last edited by Phate on Wed Mar 20, 2013 9:47 am, edited 1 time in total.

danidelrr
Posts: 5
Joined: Tue Mar 19, 2013 4:52 pm

Re: Cross-Compiling applications for Raspbian

Tue Mar 19, 2013 5:37 pm

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

Phate
Posts: 5
Joined: Tue Mar 19, 2013 3:49 pm

Re: Cross-Compiling applications for Raspbian

Wed Mar 20, 2013 9:46 am

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

danidelrr
Posts: 5
Joined: Tue Mar 19, 2013 4:52 pm

Re: Cross-Compiling applications for Raspbian [solved]

Wed Mar 20, 2013 9:54 am

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

sedonami
Posts: 17
Joined: Wed Jan 08, 2014 5:20 pm

Re: Cross-Compiling applications for Raspbian

Mon Jan 13, 2014 5:01 pm

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

mattc
Posts: 7
Joined: Fri Oct 11, 2013 2:27 am

Re: Cross-Compiling applications for Raspbian [solved]

Mon Jun 15, 2015 2:42 pm

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.

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 3 guests