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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With