logIt Log Around The Clock

Cross-Compiling for Ubuntu ARM by ffmpeg Example

This has been a delayed post since I only figure out how to solve configure error just now. It wasn’t really necessary to cross-compile last year because compiling ffmpeg directly on the ARM-board finished overnight (despite the low CPU). Anyway, in this post I’m still using the board to easily retrieve package dependencies from Ubuntu ARM repository. Toolchain used is arm-linux-gnueabi-gcc-. The following steps will apply in general:

  1. download source file (that is ffmpeg in this example)
  2. retrieve development library/build dependecies
  3. place header files and dependency libraries into toolchain path
  4. configure with toolchain
  5. make and create .deb installer package with checkinstall
cross-compile-desktop-and-arm-board-illustration.png

cross-compile: Illustration of what's done on ARM-board and what's done on desktop

Prior to anything, install Linaro toolchain by adding their repo first:

$ sudo add-apt-repository ppa:linaro-maintainers/toolchain
$ sudo apt-get install gcc-arm-linux-gnueabi

A complete guide on how to compile ffmpeg can be found in their wiki. It applies generally. So, I’ll just skip to following configure:

[ubuntu-desktop]$ ./configure --cross-prefix=arm-linux-gnueabi- --enable-cross-compile --target-os=linux --arch=arm  --cpu=cortex-a8 --extra-cflags='-march=armv7-a -mfpu=neon -mfloat-abi=softfp' --enable-libtheora

As an example, the above configure requires Theora libraries. libtheora-dev itself requires libogg-dev. Use apt-get on the board to get them from Ubuntu ARM repository. Get the .deb files from /var/cache/apt/archives/ of the ARM-board to your desktop and extract them as root:

[root@ubuntu-desktop]$ dpkg -x libogg-dev_1.2.2~dfsg-1ubuntu1_armel.deb /usr/local/cross-compile
[root@ubuntu-desktop]$ dpkg -x libtheora-dev_1.1.1+dfsg.1-3_armel.deb /usr/local/cross-compile

The above /usr/local/cross-compile is just a temporary directory. The toolchain needs header files and dependency libraries to be placed inside /usr/arm-linux-gnueabi/include/ and /usr/arm-linux-gnueabi/lib/ consecutively. In my case I created the following link for header’s include:

[root@ubuntu-desktop]$ cd /usr/arm-linux-gnueabi/include
[root@ubuntu-desktop]$ ln -s /usr/local/cross-compile/usr/include/theora
[root@ubuntu-desktop]$ ln -s /usr/local/cross-compile/usr/include/ogg

and copied these from /usr/local/cross-compile/usr/lib:

libogg.a
libogg.so
libtheora.a
libtheoradec.a
libtheoradec.la
libtheoradec.so
libtheoraenc.a
libtheoraenc.la
libtheoraenc.so
libtheora.la
libtheora.so

After successful configure, run make (this will take some time), and then pack the whole working directory to the ARM-board. Instead of doing make install in the ARM-board, use checkinstall to install and create the .deb package. This way we can make use of dpkg to uninstall or re-install in the manner of package manager.

[root@beagleboard]$ sudo checkinstall --pkgname=ffmpeg --pkgversion="5:$(./version.sh)" \
     --backup=no --deldoc=yes --default

Please mind that even if we put “--install=no“, the above checkinstall will overwrite all ffmpeg binaries in /usr/local/bin/. This is the reason why I move the process to the ARM-board: to keep other running version on my desktop stays as it is.

Check the test of streaming from our cross-compiled ffmpeg in previous post.

A Little History

When first attempt to configure exited with ERROR: libtheora not found, I found the following test failed in the output log:

$ arm-linux-gnueabi-gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mcpu=cortex-a8 -std=c99 -fomit-frame-pointer -marm -pthread -E -o /tmp/ffconf.UdYctJgq.o /tmp/ffconf.mwXpf9Tl.c
...
/usr/lib/gcc/arm-linux-gnueabi/4.6.1/../../../../arm-linux-gnueabi/bin/ld: cannot find -ltheoraenc
/usr/lib/gcc/arm-linux-gnueabi/4.6.1/../../../../arm-linux-gnueabi/bin/ld: cannot find -ltheoradec
/usr/lib/gcc/arm-linux-gnueabi/4.6.1/../../../../arm-linux-gnueabi/bin/ld: cannot find -logg

What was inside the above temporary file (/tmp/ffconf.mwXpf9Tl.c):

1
2
#include <theora/theoraenc.h>
int x;

You can run that test to check whether all dependencies are met.


8 thoughts on “Cross-Compiling for Ubuntu ARM by ffmpeg Example

  1. Alex

    Hello,
    I need to cross-compile the libavg-1.7.0 for Ebv beagle board

    can you help me

  2. Arif Post author

    If processing time doesn’t bother you, you can compile inside the Beagle Board itself. If the board runs Ubuntu ARM, install build-essential from the repo and you’re good to go the same as compiling on the desktop. I haven’t try libavg so I don’t know how long it would take compiling directly on the board.

    Will tell you when I had the chance.

  3. Alex

    Can you help me about this error:

    /usr/lib/gcc/arm-linux-gnueabi/4.4.5/../../../../arm-linux-gnueabi/bin/ld: cannot find -lstdc++
    ??

  4. Arif Post author

    As you can see from my example the linker ld cannot find some Theora libraries needed:

    /usr/lib/gcc/arm-linux-gnueabi/4.6.1/../../../../arm-linux-gnueabi/bin/ld: cannot find -ltheoraenc
    

    What I do is copy:

    libtheoraenc.a
    libtheoraenc.la
    libtheoraenc.so
    

    into /usr/local/cross-compile/usr/lib where the linker will look for those.

    In your case, I think what’s missing according to the linker is what’s listed here http://packages.ubuntu.com/precise/all/libstdc++6-armel-cross/filelist:

    /usr/arm-linux-gnueabi/lib/libstdc++.so.6
    /usr/arm-linux-gnueabi/lib/libstdc++.so.6.0.16

    I used 4.6.1 for the toolchain by the way, it is weird the way that it missed out libstdc++: a standard in compiling.

  5. Anandhakrishnan R

    Hi,
    I am getting the following error while linking the codes, Kindly give me a suggestion to resolve this linker error.,
    /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: cannot find -lasound
    /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: cannot find -lgstapp-0.10
    /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: cannot find -lgstbase-0.10
    /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: cannot find -lgstreamer-0.10
    /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: cannot find -lgobject-2.0
    /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: cannot find -lgmodule-2.0
    /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: cannot find -lgthread-2.0
    /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: cannot find -lxml2
    /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: cannot find -lglib-2.0
    collect2: ld returned 1 exit status
    make: *** [avbd] Error 1

  6. Anandhakrishnan R

    Hello arif,
    Thanks for your attention on my question.

    Do I have to include the following locations in make file while linking the object files as you have mentioned in your previous comment.,

    /usr/arm-linux-gnueabi/lib/libstdc++.so.6
    /usr/arm-linux-gnueabi/lib/libstdc++.so.6.0.16
    /usr/share/doc/libstdc++6-armel-cross

    I am looking forward to your comment to resolve the linking problem.

    Thank you,

Leave a Reply