1

I am trying to cross compile Apache Portable Run-time library APR-1.5.2 lib for ARM platform. I am following below steps.

./configure --host=aarch64-unknown-linux-gnu CC=aarch64-unknown-linux-gnu-gcc
make 

I am not getting any error in configure and make but when i try to link it to my code i am getting linking error.

#include <iostream>
#include <stdio.h>
using namespace std;

#include "apr_general.h"
#include "apr_network_io.h"
#include "apr_strings.h"

int main(){
    apr_initialize();
    std::cout<<"Welcome Program compiling  "<<std::endl;
    return 0;
}

When i am compiling the code using cross compiler getting error.

aarch64-unknown-linux-gnu-g++ -o Test -I ../../../../Static_APR/apr-1.5.2/include DAS.cpp ../../../../Static_APR/apr-1.5.2/.libs/libapr-1.a -lpthread

**apr-1.5.2/.libs/libapr-1.a(start.o): Relocations in generic ELF (EM: 62)**

Code compiles fine with g++.

g++ -o Test -I ../../../../Static_APR/apr-1.5.2/include DAS.cpp ../../../../Static_APR/apr-1.5.2/.libs/libapr-1.a -lpthread

Why APR lib didn't built for arm (cross compiler) even though i have used CC=aarch64-unknown-linux-gnu-gcc

Can anyone help me with correct way to build APR for cross compilation?

jww
  • 97,681
  • 90
  • 411
  • 885

1 Answers1

1

I am following below steps.

./configure --host=aarch64-unknown-linux-gnu CC=aarch64-unknown-linux-gnu-gcc
make

Your ./configure should include a --build. --host is the machine you are compiling for. Also see How To Configure for Android? on the Autoconf mailing list. Maybe something like:

export CPP=aarch64-unknown-linux-gnu-cpp
export CC=aarch64-unknown-linux-gnu-gcc
export CXX=aarch64-unknown-linux-gnu-g++
export LD=aarch64-unknown-linux-gnu-ld
export AR=aarch64-unknown-linux-gnu-ar
export AS=aarch64-unknown-linux-gnu-as
export RANLIB=aarch64-unknown-linux-gnu-ranlib

export CFLAGS="..."
export CXXFLAGS="..."

./configure --build=`config.guess` --host=aarch64-unknown-linux-gnu 

The snippet above should ensure all the tools are available. You may need to add CFLAGS and CXXFLAGS with the appropriate header location; and an LDFLAGS with the appropriate library location.

You should verify the program for RANLIB. Its may not be what you think. For example, on one version of Ubuntu for ARM it is:

export RANLIB=aarch64-unknown-linux-gcc-ranlib-4.7

You may need to find config.guess:

$ find /usr -name 'config.guess'
/usr/lib/rpm/redhat/config.guess
/usr/share/automake-1.15/config.guess
...

Finally, you might find these scripts useful. They help build another library by setting paths and setting tools: setenv-android.sh and setenv-embedded.sh.

jww
  • 97,681
  • 90
  • 411
  • 885
  • Thanks for the information As per my understanding and GCC documentation --build is the machine you are building on --host is the machine you are building for --target is the machine that GCC will produce binary for – Vinay Patel Jun 22 '17 at 01:59
  • 1
    @VinayPatel - My bad, sorry about that. According to [How To Configure for Android?](https://lists.gnu.org/archive/html/autoconf/2013-10/msg00003.html) on the Autoconf mailing list, you need to use both `--host` and `--build`. `--target` is for building compilers. I'm going to change the answer. – jww Jun 22 '17 at 02:07