4

I am on x86 trying to cross compile a apache thrift program written in C++ for armhf. I installed gcc-arm-linux-gnueabihf and g++-arm-linux-gnueabihf through apt-get, but when I use them to compile my program, I get

skipping incompatible /usr/local/lib/libthrift.so when searching for -lthrift

so I tried configuring thrift to compile a armhf-compatible libthrift.so using this guide, so in bash:

./configure CXX=arm-linux-gnueabihf-g++ CC=arm-linux-gnueabihf-gcc --prefix=/BBB/thrift --host=arm-linux-gnueabihf --with-cpp CFLAGS="-g -O2 -I$DIR/include" LDFLAGS="-L$DIR/lib

but then I got:

checking for libevent >= 1.0... configure: error: in 'home/xic/thrift-0.9.0': configure: error: cannot run test program while cross compiling

so then I successfully compiled libevent, but it still wouldn't work. Looking into thrift's config.log, I see

/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lfl collect2: ld returned 1 exit status

so apparently I need to cross-compile flex as well. Is this really the best way of doing this, or are there any faster/easier ways?

ps. I am cross-compiling for the Beaglebone Black, which uses armhf

Community
  • 1
  • 1
woojoo666
  • 7,801
  • 7
  • 45
  • 57

2 Answers2

8

On my system, I installed libfl by running the following command, which should be easier than manually cross-compiling flex.

sudo xapt -a armhf -m libfl-dev

In order to fix the cannot run test program while cross compiling problem, you can either build Thrift without libevent support (if that is an option for you) by passing --without-libevent to configure, or you can modify aclocal/ax_lib_event.m4 by replacing the use of AC_RUN_IFELSE with AC_LINK_IFELSE. Note that you will have to make a similar change in aclocal/ax_lib_zlib.m4 unless you pass --without-zlib to configure. Don't forget to run autoconf after modifying the files in aclocal.

After making these changes you will likely encounter these compile errors:

/usr/arm-linux-gnueabihf/include/c++/4.6.3/cstdlib:119:11: error: '::malloc' has not been declared /usr/arm-linux-gnueabihf/include/c++/4.6.3/cstdlib:127:11: error: '::realloc' has not been declared

IMO, the easiest way to fix this is by removing the following lines from configure.ac:

AC_FUNC_MALLOC
AC_FUNC_REALLOC

Again, you'll have to run autoconf after deleting the lines from configure.ac.

Finally, you can re-run configure with your chosen options. On my system, I ran:

./configure --host=arm-linux-gnueabihf --with-cpp --without-tests \
   --without-qt4 --without-c_glib --without-ruby --without-python

You will need the --without-tests option to avoid problems caused by the build attempting to run armhf test binaries on your x86 build machine.

I passed the remaining --without-* options to avoid having to install extra dependencies. If you don't require QT, Glib, Ruby, and Python support, I recommend you do the same to simplify your build.

Tim
  • 336
  • 2
  • 8
  • 3
    And for the latest thrift, turn off tests is `--enable-tests=no` – wilbeibi Jan 20 '16 at 01:56
  • At the time I was trying to do this, it didn't work correctly for --without-tests. They fixed it in more recent versions as indicated by @wilbeibi – Svartalf May 21 '19 at 17:07
3

Thrift 0.9.0 is broken for cross compilation- it's got raftloads of static paths in the Autoconf test scripting.

There is a bug in their Jira on the subject, but things haven't progressed very far (Basically asking if I'd set the --includedir of all things... (Hint: Cross compile doesn't use you dinking around with that on an Autotools config- and the first thing they should've done was go looking for fixed paths off of the host))

You can't turn off PHP building which screws up even further than this. Shame, really, I kind-of needed a one-stop-shop for this and Google and the community at large have dropped the ball on this (RPC is a joke...how many differing implementations- and none of them support C/C++/Python/C# at the same time compatibly...).

Svartalf
  • 2,512
  • 2
  • 14
  • 14
  • Thanks. I ended up compiling natively on the beaglebone, but because the apache site doesn't give the package names for opkg (they use apt-get), I had to search for them individually. RPC documentation is seriously lacking... – woojoo666 Aug 21 '13 at 07:19
  • Yeah, they only recently did work on sorting out at least part of the screwups on cross compilation (If only they'd quit using Autotools...sigh...) within the last three weeks, based on the emails I recently got on the bug I filed. It's got potential, but it's not getting the care it needs- including the documentation. – Svartalf Mar 25 '14 at 17:58