You are not logged in.

#1 2018-02-21 14:15:57

spwork
Member
Registered: 2018-02-21
Posts: 19

[SOLVED]How to generate a real linux executable file

I 'm newer programming with linux,i use cmake and make compile Urho3d sample, it generate a lot of file,such as 01_Hello World.
but the filetype of 01_Hello World is ELF 64-bit LSB shared object,
how can i generate a 01_Hello World the type is ELF 64-bit LSB executable

Last edited by spwork (2018-02-21 17:03:40)

Offline

#2 2018-02-21 14:21:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: [SOLVED]How to generate a real linux executable file

https://bbs.archlinux.org/viewtopic.php?id=57855

What is in your makefile or your cmake input?  It sounds like you compiled but have not linked the object file(s).

With modern compilers these two steps are often blurred into one, especially for simple single-file projects:

gcc -o myexecutable mysource.c

That will compile and link and produce an executable binary.

gcc mysource.c

This will just compile, and will result in an 'a.out' object file that still needs to be linked.

Last edited by Trilby (2018-02-21 14:23:21)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2018-02-21 14:31:41

spwork
Member
Registered: 2018-02-21
Posts: 19

Re: [SOLVED]How to generate a real linux executable file

test.c
int main()
{
return 0;
}
gcc -0 test test.c
i use file check the type is says:  myexecutable: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=7e4301a171f116accd1bdaf1e8391760991af197, not stripped

Offline

#4 2018-02-21 14:37:10

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: [SOLVED]How to generate a real linux executable file

Yes, that's normal.  It is an executable.  If you want a static binary:

gcc -static -o test test.c

But unless you really know what you are doing and why, you shouldn't try to use static linking.

You may want to run `file` on any "real linux executable" under /usr/bin/ as a reference.

EDIT: hmm, I did just find that the relevant field of `file` output sometimes says "shared object" and sometimes "executable" for common binaries in /usr/bin.  I'm not sure exactly what the difference is that's triggering different output from `file`, but they are all equally "real" executables.

Last edited by Trilby (2018-02-21 14:43:42)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2018-02-21 14:38:37

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,466

Re: [SOLVED]How to generate a real linux executable file

spwork, notice that's a lower case 'o', not a zero.

Offline

#6 2018-02-21 14:47:17

spwork
Member
Registered: 2018-02-21
Posts: 19

Re: [SOLVED]How to generate a real linux executable file

I 'm using gnome and a visual file manager double click the test file,but it can't execute,
and i find out a ELF 64-bit LSB executable file a execute when double click ,so i ask the question
both two types can execute by use ./test ,but only ELF 64-bit LSB executable can execute when double clicked.

Offline

#7 2018-02-21 14:49:34

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: [SOLVED]How to generate a real linux executable file

spwork wrote:

I 'm using gnome and a visual file manager double click the test file,but it can't execute,
and i find out a ELF 64-bit LSB executable file a execute when double click ,so i ask the question
both two types can execute by use ./test ,but only ELF 64-bit LSB executable can execute when double clicked.

There are two parts to this: first, how do you know your `test` program doesn't execute.  Even if it does, it does absolutely nothing, so there'd be no way to know.  Does it run from a terminal (meaning no error code and a return value of zero)?

Now if your file manager isn't properly launching functional binaries when they are clicked, that really has nothing to do with the binaries, but is a bug in the file manager.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2018-02-21 15:00:11

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [SOLVED]How to generate a real linux executable file

Your shared object declares an interpreter which is visible in your file output. This means it is a dynamically linked executable and not a shared library. (To be exact, it could be both at the same time as well)

interpreter /lib64/ld-linux-x86-64.so.2

Edit: You did check that you have the execute permission for the file?
https://wiki.archlinux.org/index.php/Fi … attributes

Last edited by progandy (2018-02-21 15:05:46)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#9 2018-02-21 15:01:08

Awebb
Member
Registered: 2010-05-06
Posts: 6,275

Re: [SOLVED]How to generate a real linux executable file

If you expect a console window to open Windows style, just to return zero and go away again, you're expecting the wrong thing. Even in a console you'd need to do some testing, whether it actually returned zero. Bash's various ways of saying NOT, perhaps.

Offline

#10 2018-02-21 15:03:33

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED]How to generate a real linux executable file

The `file` utility does not correctly detect PIE-enabled binaries as binaries instead of shared objects. Current versions of our gcc toolchain enable PIE by default as part of our security hardening.

https://www.archlinux.org/news/test-sec … ssistance/

Last edited by eschwartz (2018-02-21 15:04:23)


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#11 2018-02-21 15:04:07

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: [SOLVED]How to generate a real linux executable file

Awebb wrote:

Even in a console you'd need to do some testing...

Only to know if the binary worked as intended, not to know if it was run at all.  If `./test` returns immediately to a command prompt, that means bash found the binary and ran it.  If it returns zero, that's nice.  If it returns non-zero, that's very odd ... but it still had to run to return non-zero.  As long as the shell doesn't give a comand not found or permission denied error, all is good in terms of the file being executable.

EDIT: thanks Eschwarts, that addresses my curiosity.  I wasn't too worried though as I don't read that much into `file`'s output.

Last edited by Trilby (2018-02-21 15:05:17)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#12 2018-02-21 15:27:29

spwork
Member
Registered: 2018-02-21
Posts: 19

Re: [SOLVED]How to generate a real linux executable file

Eschwartz wrote:

The `file` utility does not correctly detect PIE-enabled binaries as binaries instead of shared objects. Current versions of our gcc toolchain enable PIE by default as part of our security hardening.

https://www.archlinux.org/news/test-sec … ssistance/

how can i disable PIE and use old execute file

Offline

#13 2018-02-21 15:30:54

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED]How to generate a real linux executable file

Why do you want to do that? What does `file` mean to you anyway? Just run the file in a command prompt!

Disabling PIE will not make the program work any better, just less securely...

But if you really want to make yourself less secure, the gcc manpage describes how to do this. If you're doing C++ development you should probably try to become at least a little familiar with how the compiler works.

...

I was attempting to explain why you got output you didn't expect. I'm not saying the output is bad. hmm

Last edited by eschwartz (2018-02-21 15:32:34)


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#14 2018-02-21 15:35:33

spwork
Member
Registered: 2018-02-21
Posts: 19

Re: [SOLVED]How to generate a real linux executable file

Eschwartz wrote:

Why do you want to do that? What does `file` mean to you anyway? Just run the file in a command prompt!

Disabling PIE will not make the program work any better, just less securely...

...

I was attempting to explain why you got output you didn't expect. I'm not saying the output is bad. hmm

currently i make a old execute so it can be run when i double clicked, this time have no good way to slove this problem.

Last edited by spwork (2018-02-21 15:37:38)

Offline

#15 2018-02-21 15:42:12

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED]How to generate a real linux executable file

You've been told multiple times that that simply isn't true. Neither PIE executables nor non-PIE executables do anything when double-clicked, or else they both do but you'll never know because you ran it outside a command prompt and therefore all error and status messages were dropped.

If the program *happens* to be a GUI program, then it will either create that GUI, and everything is good, or it will not create the GUI, and you will need to run it from the command prompt in order to figure out why.

Do not develop programs from the double-click menu of your file browser. It will just make you unhappy.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#16 2018-02-21 15:42:32

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: [SOLVED]How to generate a real linux executable file

spwork wrote:

currently i make a old execute so it can be run when i double clicked, this time have no good way to slove this problem.

*headdesk*

Please first try actually listening to any of the things you are being told.  Disabling PIE will not make your binary run any differently when clicked in a file manager.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#17 2018-02-21 15:48:56

spwork
Member
Registered: 2018-02-21
Posts: 19

Re: [SOLVED]How to generate a real linux executable file

Eschwartz wrote:

You've been told multiple times that that simply isn't true. Neither PIE executables nor non-PIE executables do anything when double-clicked, or else they both do but you'll never know because you ran it outside a command prompt and therefore all error and status messages were dropped.

If the program *happens* to be a GUI program, then it will either create that GUI, and everything is good, or it will not create the GUI, and you will need to run it from the command prompt in order to figure out why.

Do not develop programs from the double-click menu of your file browser. It will just make you unhappy.

Maybe so, I used to develop it in windows and just start developing under Linux. It's an old habit.

Offline

#18 2018-02-21 15:51:38

Awebb
Member
Registered: 2010-05-06
Posts: 6,275

Re: [SOLVED]How to generate a real linux executable file

spwork wrote:

Maybe so, I used to develop it in windows and just start developing under Linux. It's an old habit.

Awebb wrote:

If you expect a console window to open Windows style, just to return zero and go away again, you're expecting the wrong thing. Even in a console you'd need to do some testing, whether it actually returned zero. Bash's various ways of saying NOT, perhaps.

Offline

#19 2018-02-21 15:54:37

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: [SOLVED]How to generate a real linux executable file

While Eschartz's point is good, I think it's somewhat tangential to the real issue.  You *think* your binary is not executing when clicked on, but the problem is there is no way to differentiate whether or not it executed when clicked in a file manager: what do you *expect* it to do?  There is nothing wrong with the test.c code you posted - that will result in a perfectly valid binary that will run from a file manager: it will just do absolutely nothing (so you seem to wrongly interpret that as not even executing).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#20 2018-02-21 15:56:18

spwork
Member
Registered: 2018-02-21
Posts: 19

Re: [SOLVED]How to generate a real linux executable file

Trilby wrote:
spwork wrote:

currently i make a old execute so it can be run when i double clicked, this time have no good way to slove this problem.

*headdesk*

Please first try actually listening to any of the things you are being told.  Disabling PIE will not make your binary run any differently when clicked in a file manager.

test.c is a sample ,i have another gui program. i want ask , Whether the method of identifying the file type is self - brought or implemented through other programs, can I solve this problem by changing a file manager

Offline

#21 2018-02-21 15:59:54

spwork
Member
Registered: 2018-02-21
Posts: 19

Re: [SOLVED]How to generate a real linux executable file

Trilby wrote:

While Eschartz's point is good, I think it's somewhat tangential to the real issue.  You *think* your binary is not executing when clicked on, but the problem is there is no way to differentiate whether or not it executed when clicked in a file manager: what do you *expect* it to do?  There is nothing wrong with the test.c code you posted - that will result in a perfectly valid binary that will run from a file manager: it will just do absolutely nothing (so you seem to wrongly interpret that as not even executing).

It really didn't run because it had a hint,it says"Unable to display "myexecutable",, not completely unresponsive, and I had other programs with GUI, which really couldn't be executed.

Last edited by spwork (2018-02-21 16:02:25)

Offline

#22 2018-02-21 16:01:29

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: [SOLVED]How to generate a real linux executable file

spwork wrote:

test.c is a sample, i have another gui program.

If you want help with that other program, you're going to have to tell us more about it - which is what I was asking about in my first post in this thread.

spwork wrote:

i want ask , Whether the method of identifying the file type is self - brought or implemented through other programs, can I solve this problem by changing a file manager

I'm sorry, I think there may be a language barrier here.  I cannot understand any of that except the very end: no I don't think using a different file manager will help.

If one of these GUI programs do not run from a file manager, first check whether they run from a terminal.  I suspect there are just problems with your GUI program in the first place: if it will not run at all, there's no point in trying to change the file manager.  When run from a terminal, it may give useful error output as to why it can't run - when executed from the filemanager, it cannot do this.

Last edited by Trilby (2018-02-21 16:05:21)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#23 2018-02-21 16:15:24

spwork
Member
Registered: 2018-02-21
Posts: 19

Re: [SOLVED]How to generate a real linux executable file

Trilby wrote:
spwork wrote:

test.c is a sample, i have another gui program.

If you want help with that other program, you're going to have to tell us more about it - which is what I was asking about in my first post in this thread.

spwork wrote:

i want ask , Whether the method of identifying the file type is self - brought or implemented through other programs, can I solve this problem by changing a file manager

I'm sorry, I think there may be a language barrier here.  I cannot understand any of that except the very end: no I don't think using a different file manager will help.

If one of these GUI programs do not run from a file manager, first check whether they run from a terminal.  I suspect there are just problems with your GUI program in the first place: if it will not run at all, there's no point in trying to change the file manager.  When run from a terminal, it may give useful error output as to why it can't run - when executed from the filemanager, it cannot do this.

I have two program ,it is called test.c and 01_Hello World
gcc test.c
./a.out can run
but can't run in visual file manager, it show a window says "could not display a.out There is no application installed for 'shared library' files.....",
gcc -no-pie test.c
./a.out can run
it also can run in visual file manager ,because it doesn't show anything.
01_Hello World is a GUI program
./01_Hello World can run,and can display it's own GUI
it also can run in visual file manager,because it can display it's own GUI
this is it,the visual file manager can't run execute with PIE,

gcc test.c and gcc -no-pie test.c generate the two file has different icon

Last edited by spwork (2018-02-21 16:23:46)

Offline

#24 2018-02-21 16:34:22

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED]How to generate a real linux executable file

Trilby wrote:

While Eschartz's point is good, I think it's somewhat tangential to the real issue.  You *think* your binary is not executing when clicked on, but the problem is there is no way to differentiate whether or not it executed when clicked in a file manager: what do you *expect* it to do?  There is nothing wrong with the test.c code you posted - that will result in a perfectly valid binary that will run from a file manager: it will just do absolutely nothing (so you seem to wrongly interpret that as not even executing).

My point is fine. tongue

Eschwartz wrote:

You've been told multiple times that that simply isn't true. Neither PIE executables nor non-PIE executables do anything when double-clicked, or else they both do but you'll never know because you ran it outside a command prompt and therefore all error and status messages were dropped.

Silently returning a new $ prompt is itself a message that the program performed as it was supposed to, and finished off by returning some exit code...

A message that forking from some file browser drops.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#25 2018-02-21 16:48:44

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: [SOLVED]How to generate a real linux executable file

spwork wrote:

gcc test.c
./a.out can run
but can't run in visual file manager, it show a window says "could not display a.out There is no application installed for 'shared library' files.....",
gcc -no-pie test.c
./a.out can run
it also can run in visual file manager

Ah, thank you.  Now you've actually described the problem.  This example does suggest a problem with the file manager you are using.  But before you ditch it, I'd suggest a slightly improved test, instead of trying to run a.out, properly compile/link the program:

gcc -o test test.c

Then `test` (not a.out) should still definitely run from ther terminal but the real test is whether your file manager still gives that error message that no application is installed for the file type.  I'm not sure if this would make any difference, but trying to run `a.out` is a bit odd, the file manager may take issue with the .out extension for all we know.

Last edited by Trilby (2018-02-21 16:49:48)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB