cnacy cnacy - 3 months ago 23
Linux Question

Error when trying to run an executable on a Linux system

I am getting an error when trying to run an executable on a Linux system.

I wrote simple application which includes the library located at

/usr/local/lib
and the header files at
/usr/local/include
.

It was compiled as below; it generated the executable.

gcc -c gd-client.c -I/usr/local/include/dbus-1.0/dbus -L/usr/local/lib/ -o gd-client


But when I try to run the executable, it gives me the error shown below.

cannot execute binary file: Exec format error



  1. It was compiled using
    gcc
    and linked with actual path for both library and header files. Does it matter where the executable is located when I run it?
    I also tried to place it under
    /usr/local/bin/
    but I am
    still getting same error.

  2. As it was compiled and and is executing on the same machine, the OS and the cpu architecture remains the same. It should not complain.



Can anyone tell what else might be wrong?

Edited:
the output of
file /bin/sh gd-client
:

/bin/sh: symbolic link to dash
gd-client: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not
stripped

$ file /bin/dash
/bin/dash: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),

dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for

GNU/Linux 2.6.32,
BuildID[sha1]=504637666875a5d526ef51acfe601c99efc99114, stripped
$ /bin/ls
gd-client gd-client.c

$ file /bin/dash gd-client
/bin/dash: ELF 64-bit LSB shared object, x86-64, version 1
(SYSV), dynamically linked, interpreter /lib64/ld-linux-
x86-64.so.2, for GNU/Linux 2.6.32,
BuildID[sha1]=504637666875a5d526ef51acfe601c99efc99114, stripped
gd-client: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not
stripped


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with- kgversion='Ubuntu 5.3.1-14ubuntu2' --with- bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --
program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ -- enable- clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-
java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-
amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --
with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2)

Answer

gcc -c doesn't generate executables; it generates object files. Remove the -c if you want an executable.