Search code examples
gccfortrancpu-architecturegfortranarm64

Why do I get 'Error executing binary file' despite compiling for the correct architecture?


I am trying to compile a C/Fortran program using gcc and gfortran for aarch64. Despite successfully completing compiling, I cannot execute the binary: I get bash: .: gMultiwfn: cannot execute binary file when I try running it using . gMultiwfn. Using sudo -s then running . gMultiwfn also fails.

I am new to Fortran and compiling generally, but I can't find anything online about this issue: everything just says 'compile it for the correct architecture'.

I am using a Makefile to compile, which runs aarch64-linux-gnu-gfortran -O2 -fopenmp -ffree-line-length-none -cpp define.o util.o plot.o Bspline.o sym.o libreta.o function.o GUI.o sub.o integral.o Lebedev-Laikov.o DFTxclib.o edflib.o fileIO.o spectrum.o DOS.o Multiwfn.o 0123dim.o LSB.o population.o orbcomp.o bondorder.o topology.o excittrans.o otherfunc.o otherfunc2.o otherfunc3.o surfana.o procgriddata.o AdNDP.o fuzzy.o CDA.o basin.o orbloc.o visweak.o EDA.o atmraddens.o NAONBO.o minpack.o ean.o hrr_012345.o eanvrr_012345.o boysfunc.o ./dislin_d-11.5.a -lXm -lXt -lX11 -lGL -lblas -llapack -o gMultiwfn. The .o files have been compiled in previous steps in the Makefile, which all return the same debug outputs: they are aarch64. They were compiled using aarch64-linux-gnu-gfortran -O2 -fopenmp -ffree-line-length-none -cpp -c [whatever file].f90.

Some output from various debug commands (please tell me if you need more info):

$ file gMultiwfn
gMultiwfn: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID\[sha1\]=ef34baade8dbbfd9f99e970ebec8e7c6468368a2, for GNU/Linux 3.7.0, not stripped

$ ls -l gMultiwfn
-rwxrwxrwx 1 admin admin 8644192 Jun  8 12:54 gMultiwfn

$ uname -m
aarch64

$ objdump -i gMultiwfn
BFD header file version (GNU Binutils for Debian) 2.40

I tried using aarch64-linux-gnu-gfortran and aarch64-linux-gnu-gcc instead of just gfortran and gcc, but I still cannot execute the file.


Solution

  • I get bash: .: gMultiwfn: cannot execute binary file when I try running it using . gMultiwfn.

    That is not how you run an executable. Compare:

    Wrong:

    /bin$ . gcc --version
    bash: .: /usr/bin/gcc: cannot execute binary file
    

    Right:

    /bin$ ./gcc --version
    gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0
    Copyright (C) 2023 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
    

    Note too that ./prog is how you will run prog when that is the name of a file in the current directory (./) that happens to be executable. If you wish to run a program that is not in the current directory but can be found in your PATH then just run $ prog, like:

    ~$ gcc --version
    gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0
    Copyright (C) 2023 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.