[英]Error when trying to run an executable on a Linux system
嘗試在Linux系統上運行可執行文件時出現錯誤。
我編寫了一個簡單的應用程序,其中包括位於/usr/local/lib
和位於/usr/local/include
的頭文件。
編譯如下: 它生成了可執行文件。
gcc -c gd-client.c -I/usr/local/include/dbus-1.0/dbus -L/usr/local/lib/ -o gd-client
但是,當我嘗試運行可執行文件時,它給了我下面顯示的錯誤。
cannot execute binary file: Exec format error
它是使用gcc
並與庫和頭文件的實際路徑鏈接。 運行可執行文件的位置是否有關系? 我也嘗試將其放在/usr/local/bin/
但是仍然出現相同的錯誤。
由於它是在同一台計算機上編譯並執行的,因此操作系統和cpu體系結構保持不變。 它不應該抱怨。
誰能告訴我還有什么問題嗎?
編輯: 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)
gcc -c
不會生成可執行文件; 它生成目標文件。 如果需要可執行文件,請刪除-c
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.