为armhf交叉编译Apache Thrift程序

woo*_*666 4 thrift cross-compiling beagleboard

我在x86上尝试交叉编译用C++编写的armhf的apache thrift程序.我安装gcc-arm-linux-gnueabihfg++-arm-linux-gnueabihf通过apt-get,但是当我使用它们来编译我的程序时,我得到了

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

所以我尝试使用本指南配置thrift来编译armhf兼容的libthrift.so ,所以在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

但后来我得到了:

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

所以我成功编译了libevent,但它仍然行不通.看看节俭config.log,我明白了

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

显然我也需要交叉编译flex.这真的是最好的方法吗,还是有更快/更简单的方法?

PS.我正在为使用armhf的Beaglebone Black进行交叉编译

小智 7

在我的系统上,我libfl通过运行以下命令来安装,这应该比手动交叉编译flex更容易.

sudo xapt -a armhf -m libfl-dev
Run Code Online (Sandbox Code Playgroud)

为了解决这个cannot run test program while cross compiling问题,您可以通过传递--without-libevent来构建Thrift而不需要libevent支持(如果这是一个选项)configure,或者您可以aclocal/ax_lib_event.m4通过替换AC_RUN_IFELSEwith 的使用来修改AC_LINK_IFELSE.请注意,aclocal/ax_lib_zlib.m4除非您--without-zlib转到,否则您必须进行类似的更改configure.autoconf修改文件后不要忘记运行aclocal.

进行这些更改后,您可能会遇到以下编译错误:

/usr/arm-linux-gnueabihf/include/c++/4.6.3/cstdlib:119:11:错误:':: malloc'尚未声明/usr/arm-linux-gnueabihf/include/c++/4.6.3/cstdlib:127:11:错误:':: realloc'尚未声明

IMO,最简单的解决方法是删除以下行configure.ac:

AC_FUNC_MALLOC
AC_FUNC_REALLOC
Run Code Online (Sandbox Code Playgroud)

同样,你必须autoconf在删除行之后运行configure.ac.

最后,您可以configure使用所选的选项重新运行.在我的系统上,我运行:

./configure --host=arm-linux-gnueabihf --with-cpp --without-tests \
   --without-qt4 --without-c_glib --without-ruby --without-python
Run Code Online (Sandbox Code Playgroud)

您将需要--without-tests选项以避免因构建尝试在x86构建计算机上运行armhf测试二进制文件而导致的问题.

我传递了剩余的--without-*选项,以避免必须安装额外的依赖项.如果您不需要QT,Glib,Ruby和Python支持,我建议您也这样做以简化构建.

  • 对于最新的节俭,关闭测试是`--enable-tests = no` (3认同)