I am using Linux Ubuntu 64-bit and compiling C code to be run in a Linux Armbian 32-bit system. I am using:
arm-linux-gnueabi-gcc -c test.c -o test.o
arm-linux-gnueabi-g++ -o test test.o -static
When I test the code on Ubuntu I use gcc/g++, but when I'm finished I compile an link with above "arm.." and scp "test" to the Armbian 32-system.
This works with simple "Hello World" -code provide the the "-static" is there. If I leave "-static" out even the simple executable won't run on the Armbian 32-system.
But if I include code using, say, "gethostbyname" I'll get get warning and the resulting executable won't run on the Armbian 32-bit. What should my compile & link be so that I could compile in Ubuntu 64-bit and copy the executable to the Armbian 32-bit?
The only solution that I've found is do all compile & link on the Armbian, but I want to avoid that since all my tools are not there. Here is the code
#include <stdio.h>
#include <netdb.h>
int main(int argc, char *argv[])
{
struct hostent *lh = gethostbyname("localhost");
if (lh)
puts(lh->h_name);
else
herror("gethostbyname");
return 0;
}
When linking with:
arm-linux-gnueabi-g++ -o test test.o -static -lrt
I get a warning:
test.c:(.text+0x18): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the libc version used for linking
When running it on 32-bit Armbian I get an error:
gethostbyname: Resolver internal error
When I link with:
arm-linux-gnueabi-g++ -o test test.o -lrt
I don't get any warning. However when running it on 32-bit Armbian I get an error:
unable to execute ./test: No such file or directory