Apache Cross compilation error ./gen_test_char: Unable to execute binary
I have taken enough time to find a solution to this error. When trying to cross-compile Apache for hand (I'm sure this can happen for many other architectures), I get this error using in the server folder:
./gen_test_char: cannot execute binary file
This means that Apache is trying to compile this test_char.h generator for a real device, while I need to run it on my Ubuntu where I am cross-compiling. Ubuntu doesn't recognize the compiled gen_test_char as executable, so I need to compile it correctly for Ubuntu.
source to share
I searched and searched and found several attempts to fix it but none of them worked. Most of them were patches offered directly from the Apache dev team.
But I finally came across this list of Apache emails . It offers a straightforward solution that the fixes cannot provide.
Compile the gen_test_char application before trying to cross-compile Apache. So I did. And followed the suggestions and it worked like a charm.
instead, just compile gen_test_char.c 1st with something like: gcc -Wall -O2 -DCROSS_COMPILE gen_test_char.c -s -o gen_test_char then run it and put your output in your include folder (or where normaly put it);
and after that compilation run it to get the desired output with:
./gen_test_char > test_char.h
source to share
These are the specific steps that worked for me based on the Apache mailing list that CaptainBli linked in his answer. I am cross-compiling for ARM from an x86_64 machine.
First, set up and run make to cross-compile. After compilation fails due to a problem with the gen_test_char executable, go to the folder tools/
and recompile gen_test_char for your build system:
$ pwd
.../apr-1.7.0
$ cd tools/
$ gcc -Wall -O2 -DCROSS_COMPILE gen_test_char.c -s -o gen_test_char
Now run make
as you did earlier and it will start where it left off, except that this time it will use the executable you gen_test_char
created to run on your build system. Don't start over make clean
- this will destroy the executable you just created and you will be back to where you started.
source to share