How to run binary file in Linux

前端 未结 11 1038
执念已碎
执念已碎 2021-02-01 18:15

I have a file called commanKT and want to run it in a Linux terminal. Can someone help by giving the command to run this file? I tried ./commonRT but I

11条回答
  •  -上瘾入骨i
    2021-02-01 18:43

    This is an answer to @craq :

    I just compiled the file from C source and set it to be executable with chmod. There were no warning or error messages from gcc.

    I'm a bit surprised that you had to 'set it to executable' -- my gcc always sets the executable flag itself. This suggests to me that gcc didn't expect this to be the final executable file, or that it didn't expect it to be executable on this system.

    Now I've tried to just create the object file, like so:

    $ gcc -c -o hello hello.c
    $ chmod +x hello
    

    (hello.c is a typical "Hello World" program.) But my error message is a bit different:

    $ ./hello
    bash: ./hello: cannot execute binary file: Exec format error`
    

    On the other hand, this way, the output of the file command is identical to yours:

    $ file hello
    hello: ELF 64-bit LSB  relocatable, x86-64, version 1 (SYSV), not stripped
    

    Whereas if I compile correctly, its output is much longer.

    $ gcc -o hello hello.c
    $ file hello
    hello: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=131bb123a67dd3089d23d5aaaa65a79c4c6a0ef7, not stripped
    

    What I am saying is: I suspect it has something to do with the way you compile and link your code. Maybe you can shed some light on how you do that?

提交回复
热议问题