Entware / Entware-ng

Entware-ng
GNU General Public License v2.0
1.21k stars 153 forks source link

Can't execute binary compiled with entware gcc #783

Closed mcandre closed 7 years ago

mcandre commented 7 years ago

Package: gcc

For existing package:

Platform:

# opkg list-installed | grep gcc
gcc - 6.3.0-1
libgcc - 6.3.0-6

Example hello.c:

#include "stdlib.h"
#include "stdio.h"

int main() {
  printf("Hello World!\n");
  exit(0);
}

Example entware setup, such as in Docker using the openwrt v12.09 rootfs tarball:

export PATH="/opt/bin:/opt/sbin:$PATH"
wget -O - http://pkg.entware.net/binaries/x86-64/installer/entware_install.sh | /bin/sh && \
    opkg update && \
    opkg install gcc && \
    gcc_env.sh

Then I run gcc -o hello hello.c, which produces a binary. I'm not 100% sure that the hello binary produced correctly targets the x86-64 architecture. gcc -v appears to be configured to produce x86-64 binaries by default. ldd from entware opkg can't read the binary, which usually indicates that a binary is targeting a different platform than what the host is capable of handling (just x86-64 in this case). readelf -d hello shows the binary linking against libgcc, for what it's worth.

And entware file thinks that the binary is x86-64, so I'm scratching my head why it won't run.

# opkg update && opkg install file
# file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, not stripped
mcandre commented 7 years ago

Ah, I see the workaround posted at https://github.com/Entware-ng/Entware-ng/issues/718#issuecomment-316780470 , that is, explicitly pass $CFLAGS and $LDFLAGS to gcc. Stinks that explicit passing of $(CFLAGS) and $(LDFLAGS) to gcc is required in Makefile's, but so be it, at least it works!

zyxmon commented 7 years ago

https://github.com/Entware-ng/Entware-ng/wiki/Using-gcc-(native-compilation) was published a couple of years ago.